mirror of
https://github.com/fluencelabs/redis
synced 2025-04-02 15:51:05 +00:00
Check for \n after finding \r
This commit is contained in:
parent
32f99c5128
commit
bf9fd5ffa2
@ -712,6 +712,10 @@ int processMultibulkBuffer(redisClient *c) {
|
|||||||
if (newline == NULL)
|
if (newline == NULL)
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
|
|
||||||
|
/* Buffer should also contain \n */
|
||||||
|
if (newline-(c->querybuf) > ((signed)sdslen(c->querybuf)-2))
|
||||||
|
return REDIS_ERR;
|
||||||
|
|
||||||
/* We know for sure there is a whole line since newline != NULL,
|
/* We know for sure there is a whole line since newline != NULL,
|
||||||
* so go ahead and find out the multi bulk length. */
|
* so go ahead and find out the multi bulk length. */
|
||||||
redisAssert(c->querybuf[0] == '*');
|
redisAssert(c->querybuf[0] == '*');
|
||||||
@ -733,9 +737,6 @@ int processMultibulkBuffer(redisClient *c) {
|
|||||||
/* Setup argv array on client structure */
|
/* Setup argv array on client structure */
|
||||||
if (c->argv) zfree(c->argv);
|
if (c->argv) zfree(c->argv);
|
||||||
c->argv = zmalloc(sizeof(robj*)*c->multibulklen);
|
c->argv = zmalloc(sizeof(robj*)*c->multibulklen);
|
||||||
|
|
||||||
/* Search new newline */
|
|
||||||
newline = strchr(c->querybuf+pos,'\r');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
redisAssert(c->multibulklen > 0);
|
redisAssert(c->multibulklen > 0);
|
||||||
@ -743,27 +744,30 @@ int processMultibulkBuffer(redisClient *c) {
|
|||||||
/* Read bulk length if unknown */
|
/* Read bulk length if unknown */
|
||||||
if (c->bulklen == -1) {
|
if (c->bulklen == -1) {
|
||||||
newline = strchr(c->querybuf+pos,'\r');
|
newline = strchr(c->querybuf+pos,'\r');
|
||||||
if (newline != NULL) {
|
if (newline == NULL)
|
||||||
if (c->querybuf[pos] != '$') {
|
|
||||||
addReplyErrorFormat(c,
|
|
||||||
"Protocol error: expected '$', got '%c'",
|
|
||||||
c->querybuf[pos]);
|
|
||||||
setProtocolError(c,pos);
|
|
||||||
return REDIS_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = string2ll(c->querybuf+pos+1,newline-(c->querybuf+pos+1),&ll);
|
|
||||||
if (!ok || ll < 0 || ll > 512*1024*1024) {
|
|
||||||
addReplyError(c,"Protocol error: invalid bulk length");
|
|
||||||
setProtocolError(c,pos);
|
|
||||||
return REDIS_ERR;
|
|
||||||
}
|
|
||||||
pos += newline-(c->querybuf+pos)+2;
|
|
||||||
c->bulklen = ll;
|
|
||||||
} else {
|
|
||||||
/* No newline in current buffer, so wait for more data */
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Buffer should also contain \n */
|
||||||
|
if (newline-(c->querybuf) > ((signed)sdslen(c->querybuf)-2))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (c->querybuf[pos] != '$') {
|
||||||
|
addReplyErrorFormat(c,
|
||||||
|
"Protocol error: expected '$', got '%c'",
|
||||||
|
c->querybuf[pos]);
|
||||||
|
setProtocolError(c,pos);
|
||||||
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ok = string2ll(c->querybuf+pos+1,newline-(c->querybuf+pos+1),&ll);
|
||||||
|
if (!ok || ll < 0 || ll > 512*1024*1024) {
|
||||||
|
addReplyError(c,"Protocol error: invalid bulk length");
|
||||||
|
setProtocolError(c,pos);
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos += newline-(c->querybuf+pos)+2;
|
||||||
|
c->bulklen = ll;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read bulk argument */
|
/* Read bulk argument */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user