Permalink
Browse files

only tokenize arg2, when request is redis_argeval

  • Loading branch information...
1 parent 736094c commit 199f042493ba662a21bafa15d8dd6a8e454f55e7 Manju Rajashekhar committed Jan 30, 2013
Showing with 38 additions and 16 deletions.
  1. +10 −0 scripts/redis-check.sh
  2. +28 −16 src/proto/nc_redis.c
View
@@ -468,3 +468,13 @@ printf '*2\r\n$3\r\ndel\r\n$4\r\nzfoo\r\n' | socat ${debug} ${timeout} - TCP:loc
printf '*3\r\n$6\r\nzscore\r\n$4\r\nzfoo\r\n$3\r\nbar\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
printf '*8\r\n$4\r\nzadd\r\n$4\r\nzfoo\r\n$3\r\n100\r\n$3\r\nbar\r\n$3\r\n101\r\n$3\r\nbat\r\n$3\r\n102\r\n$3\r\nbau\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
printf '*3\r\n$6\r\nzscore\r\n$4\r\nzfoo\r\n$3\r\nbar\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+
+# scripting
+
+printf '*2\r\n$4\r\neval\r\n$10\r\nreturn 123\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+printf '*3\r\n$4\r\neval\r\n$10\r\nreturn 123\r\n$1\r\n0\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+printf '*3\r\n$4\r\neval\r\n$10\r\nreturn 123\r\n$1\r\n1\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+printf '*4\r\n$4\r\neval\r\n$10\r\nreturn 123\r\n$1\r\n1\r\n$1\r\n1\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+printf '*7\r\n$4\r\neval\r\n$40\r\nreturn {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}\r\n$1\r\n2\r\n$9\r\nkey1{tag}\r\n$4\r\narg1\r\n$9\r\nkey2{tag}\r\n$4\r\narg2\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+printf '*9\r\n$4\r\neval\r\n$56\r\nreturn {KEYS[1],KEYS[2],KEYS[3],ARGV[1],ARGV[2],ARGV[3]}\r\n$1\r\n3\r\n$9\r\nkey1{tag}\r\n$4\r\narg1\r\n$9\r\nkey2{tag}\r\n$4\r\narg2\r\n$9\r\nkey3{tag}\r\n$4\r\narg3\r\n' | socat ${debug} ${timeout} - TCP:localhost:${port},shut-close
+
View
@@ -1127,7 +1127,11 @@ redis_parse_req(struct msg *r)
break;
case SW_ARG2:
- if (r->token == NULL) {
+ if (r->token == NULL && redis_argeval(r)) {
+ /*
+ * For EVAL/EVALSHA, ARG2 represents is the # key/arg pairs which must
+ * be tokenized and stored in contiguous memory.
+ */
r->token = p;
}
@@ -1147,26 +1151,34 @@ redis_parse_req(struct msg *r)
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)
+ uint32_t nkey;
+ uint8_t *chp;
+
+ /*
+ * 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;
- uint8_t *chp = r->token;
- for (; chp < p; chp++) {
- if (isdigit(*chp))
- nkeys = nkeys * 10 + (uint32_t)(*chp - '0');
- else
+ }
+
+ for (nkey = 0, chp = r->token; chp < p; chp++) {
+ if (isdigit(*chp)) {
+ nkey = nkey * 10 + (uint32_t)(*chp - '0');
+ } else {
goto error;
+ }
}
- if (nkeys == 0)
+ if (nkey == 0) {
goto error;
+ }
+
+ r->token = NULL;
}
-
- r->token = NULL;
+
state = SW_ARG2_LF;
break;

0 comments on commit 199f042

Please sign in to comment.