diff --git a/src/scripting.c b/src/scripting.c index ef00eede63e2..0a511e9817ad 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -910,6 +910,9 @@ void evalGenericCommand(redisClient *c, int evalsha) { if (numkeys > (c->argc - 3)) { addReplyError(c,"Number of keys can't be greater than number of args"); return; + } else if (numkeys < 0) { + addReplyError(c,"Number of keys can't be negative"); + return; } /* We obtain the script SHA1, then check if this function is already diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 4190a0a49f46..d0c6f5d7a4b7 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -358,6 +358,11 @@ start_server {tags {"scripting"}} { return redis.call("get", "key") } 0 } {12039611435714932082} + + test {Verify negative arg count is error instead of crash (issue #1842)} { + catch { r eval { return "hello" } -12 } e + set e + } {ERR Number of keys can't be negative} } # Start a new server since the last test in this stanza will kill the