summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-04-19 16:17:08 +0200
committerantirez <antirez@gmail.com>2017-04-20 07:57:44 +0200
commit278972ceb1cc24663c6acfc2654a04148a3ed26f (patch)
tree59f544d0fdf487544bf5c06d58e3c44fe5e2b291
parent2028501776dc076d6f2dbbae579ff3e77a77d637 (diff)
downloadredis-278972ceb1cc24663c6acfc2654a04148a3ed26f.tar.gz
Fix getKeysUsingCommandTable() in cluster mode.
Close #3940.
-rw-r--r--src/db.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/db.c b/src/db.c
index 760843120..86dabac8f 100644
--- a/src/db.c
+++ b/src/db.c
@@ -1133,11 +1133,24 @@ int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, in
*numkeys = 0;
return NULL;
}
+
last = cmd->lastkey;
if (last < 0) last = argc+last;
keys = zmalloc(sizeof(int)*((last - cmd->firstkey)+1));
for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
- serverAssert(j < argc);
+ if (j >= argc) {
+ /* Modules command do not have dispatch time arity checks, so
+ * we need to handle the case where the user passed an invalid
+ * number of arguments here. In this case we return no keys
+ * and expect the module command to report an arity error. */
+ if (cmd->flags & CMD_MODULE) {
+ zfree(keys);
+ *numkeys = 0;
+ return NULL;
+ } else {
+ serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
+ }
+ }
keys[i++] = j;
}
*numkeys = i;