Skip to content

Commit

Permalink
Fix EVAL crashing server when numkeys is -1 (#1568)
Browse files Browse the repository at this point in the history
The check allow we passing -1 is wrong, without
this fix, passing a -1 will crash the server.
  • Loading branch information
enjoy-binbin authored Jul 9, 2023
1 parent 2a927ce commit 506f672
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands/cmd_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CommandEvalImpl : public Commander {
int64_t numkeys = GET_OR_RET(ParseInt<int64_t>(args_[2], 10));
if (numkeys > int64_t(args_.size() - 3)) {
return {Status::NotOK, "Number of keys can't be greater than number of args"};
} else if (numkeys < -1) {
} else if (numkeys < 0) {
return {Status::NotOK, "Number of keys can't be negative"};
}

Expand Down
4 changes: 4 additions & 0 deletions tests/gocase/unit/scripting/scripting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestScripting(t *testing.T) {
rdb := srv.NewClient()
defer func() { require.NoError(t, rdb.Close()) }()

t.Run("EVAL - numkeys can't be negative", func(t *testing.T) {
util.ErrorRegexp(t, rdb.Do(ctx, "EVAL", `return redis.call('PING');`, "-1").Err(), ".*can't be negative.*")
})

t.Run("EVAL - Does Lua interpreter replies to our requests?", func(t *testing.T) {
r := rdb.Eval(ctx, `return 'hello'`, []string{})
require.NoError(t, r.Err())
Expand Down

0 comments on commit 506f672

Please sign in to comment.