Make sure error and status replies emitted by Lua scripts can never have more than a newline, otherwise it is a protocol violation and clients will desync.

This commit is contained in:
antirez
2011-05-24 19:43:11 +02:00
parent 449286a588
commit 3bb818df40
4 changed files with 39 additions and 4 deletions

View File

@ -246,10 +246,17 @@ void addReplyError(redisClient *c, char *err) {
}
void addReplyErrorFormat(redisClient *c, const char *fmt, ...) {
size_t l, j;
va_list ap;
va_start(ap,fmt);
sds s = sdscatvprintf(sdsempty(),fmt,ap);
va_end(ap);
/* Make sure there are no newlines in the string, otherwise invalid protocol
* is emitted. */
l = sdslen(s);
for (j = 0; j < l; j++) {
if (s[j] == '\r' || s[j] == '\n') s[j] = ' ';
}
_addReplyError(c,s,sdslen(s));
sdsfree(s);
}