From ff04ad914d940a3d4c8dbf3d9d19852ece820101 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Mon, 26 Aug 2024 11:47:54 +0300 Subject: [PATCH] fix: return an error when invalid number of arguments is passed. Signed-off-by: Roman Gershman --- src/core/interpreter.cc | 9 ++++++--- src/core/interpreter_test.cc | 2 ++ tests/fakeredis/test/test_mixins/test_scripting.py | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/interpreter.cc b/src/core/interpreter.cc index 5c2b04644d6e..a8d53550f497 100644 --- a/src/core/interpreter.cc +++ b/src/core/interpreter.cc @@ -464,9 +464,12 @@ int RedisReplicateCommands(lua_State* lua) { } int RedisLogCommand(lua_State* lua) { - // if the arguments passed to redis.log are incorrect - // we still do not log the error. Therefore, even if - // for the no-op case we don't need to parse the arguments + int argc = lua_gettop(lua); + if (argc < 2) { + PushError(lua, "redis.log() requires two arguments or more."); + return RaiseError(lua); + } + return 0; } diff --git a/src/core/interpreter_test.cc b/src/core/interpreter_test.cc index 818e645cc690..1fe0909fcbdb 100644 --- a/src/core/interpreter_test.cc +++ b/src/core/interpreter_test.cc @@ -484,6 +484,8 @@ TEST_F(InterpreterTest, Log) { EXPECT_EQ("nil", ser_.res); EXPECT_TRUE(Execute(R"(redis.log(redis.LOG_WARNING, 'warn'))")); EXPECT_EQ("nil", ser_.res); + EXPECT_FALSE(Execute(R"(redis.log(redis.LOG_WARNING))")); + EXPECT_THAT(error_, testing::HasSubstr("requires two arguments or more")); } TEST_F(InterpreterTest, Robust) { diff --git a/tests/fakeredis/test/test_mixins/test_scripting.py b/tests/fakeredis/test/test_mixins/test_scripting.py index 5e37a0c04f68..90211c815976 100644 --- a/tests/fakeredis/test/test_mixins/test_scripting.py +++ b/tests/fakeredis/test/test_mixins/test_scripting.py @@ -57,6 +57,7 @@ def test_script_exists_redis6(r: redis.Redis): @pytest.mark.parametrize("args", [("a",), tuple("abcdefghijklmn")]) +@pytest.mark.unsupported_server_types("dragonfly") def test_script_flush_errors_with_args(r, args): with pytest.raises(redis.ResponseError): raw_command(r, "SCRIPT FLUSH %s" % " ".join(args))