Skip to content

Commit

Permalink
Modify proto/nc_redis.c to reject EVAL/EVALSHA with 0 keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
tan-lawrence committed Jan 30, 2013
1 parent 0d38b03 commit 48f5e50
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/proto/nc_redis.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1127,6 +1127,10 @@ redis_parse_req(struct msg *r)
break; break;


case SW_ARG2: case SW_ARG2:
if (r->token == NULL) {
r->token = p;
}

m = p + r->rlen; m = p + r->rlen;
if (m >= b->last) { if (m >= b->last) {
r->rlen -= (uint32_t)(b->last - p); r->rlen -= (uint32_t)(b->last - p);
Expand All @@ -1141,6 +1145,27 @@ redis_parse_req(struct msg *r)


p = m; /* move forward by rlen bytes */ p = m; /* move forward by rlen bytes */
r->rlen = 0; r->rlen = 0;

if (redis_argeval(r)) {
// For EVAL/EVALSHA, we need to find the integer value of this
// argument. It tells us the number of keys in the script, and
// we need to error out if number of keys is 0.
// At this point, both p and m point to the end of the argument
// and r->token points to the start.
if (p - r->token <= 1)
goto error;
uint32_t nkeys = 0;
for (uint8_t *chp = r->token; chp < p; chp++) {
if (isdigit(*chp))
nkeys = nkeys * 10 + (uint32_t)(*chp - '0');
else
goto error;
}
if (nkeys == 0)
goto error;
}

r->token = NULL;
state = SW_ARG2_LF; state = SW_ARG2_LF;


break; break;
Expand Down

0 comments on commit 48f5e50

Please sign in to comment.