This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 506f6727 Fix EVAL crashing server when numkeys is -1 (#1568)
506f6727 is described below

commit 506f672742328870c1cf93b033593c6791abbcbe
Author: Binbin <[email protected]>
AuthorDate: Sun Jul 9 16:49:36 2023 +0800

    Fix EVAL crashing server when numkeys is -1 (#1568)
    
    The check allow we passing -1 is wrong, without
    this fix, passing a -1 will crash the server.
---
 src/commands/cmd_script.cc                    | 2 +-
 tests/gocase/unit/scripting/scripting_test.go | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/commands/cmd_script.cc b/src/commands/cmd_script.cc
index 4dfbca2b..54f115db 100644
--- a/src/commands/cmd_script.cc
+++ b/src/commands/cmd_script.cc
@@ -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"};
     }
 
diff --git a/tests/gocase/unit/scripting/scripting_test.go 
b/tests/gocase/unit/scripting/scripting_test.go
index 930a6210..6f8180bb 100644
--- a/tests/gocase/unit/scripting/scripting_test.go
+++ b/tests/gocase/unit/scripting/scripting_test.go
@@ -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())

Reply via email to