diff --git a/src/db.c b/src/db.c index 1991a5807..cc35f171d 100644 --- a/src/db.c +++ b/src/db.c @@ -2131,7 +2131,7 @@ int64_t getAllKeySpecsFlags(struct redisCommand *cmd, int inv) { * found in other valid keyspecs. */ int getKeysUsingKeySpecs(struct redisCommand *cmd, robj **argv, int argc, int search_flags, getKeysResult *result) { - int j, i, last, first, step; + long j, i, last, first, step; keyReference *keys; serverAssert(result->numkeys == 0); /* caller should initialize or reset it */ @@ -2191,20 +2191,20 @@ int getKeysUsingKeySpecs(struct redisCommand *cmd, robj **argv, int argc, int se } first += spec->fk.keynum.firstkey; - last = first + (int)numkeys-1; + last = first + (long)numkeys-1; } else { /* unknown spec */ goto invalid_spec; } - int count = ((last - first)+1); - keys = getKeysPrepareResult(result, result->numkeys + count); - /* First or last is out of bounds, which indicates a syntax error */ if (last >= argc || last < first || first >= argc) { goto invalid_spec; } + int count = ((last - first)+1); + keys = getKeysPrepareResult(result, result->numkeys + count); + for (i = first; i <= last; i += step) { if (i >= argc || i < first) { /* Modules commands, and standard commands with a not fixed number diff --git a/tests/unit/introspection-2.tcl b/tests/unit/introspection-2.tcl index 89cb4b122..f9885c023 100644 --- a/tests/unit/introspection-2.tcl +++ b/tests/unit/introspection-2.tcl @@ -133,6 +133,10 @@ start_server {tags {"introspection"}} { assert_equal {{k1 {RO access}} {k2 {OW update}}} [r command getkeysandflags sort k1 store k2] } + test {COMMAND GETKEYSANDFLAGS invalid args} { + assert_error "ERR Invalid arguments*" {r command getkeysandflags ZINTERSTORE zz 1443677133621497600 asdf} + } + test {COMMAND GETKEYS MEMORY USAGE} { assert_equal {key} [r command getkeys memory usage key] }