Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
scripting: no eval with negative key count
Browse files Browse the repository at this point in the history
Negative key count causes segfault in Lua functions.

Fixes redis#1842
Closes redis#1843
  • Loading branch information
mattsta committed Aug 2, 2014
1 parent f62cb0e commit 7da1992
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/scripting.c
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/scripting.tcl
Expand Up @@ -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
Expand Down

0 comments on commit 7da1992

Please sign in to comment.