From 46c31a150a0e6a67eaaf4b1e1146ec815cc1355e Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 31 Aug 2012 10:22:21 +0200 Subject: [PATCH] Scripting: require at least one argument for redis.call(). Redis used to crash with a call like the following: EVAL "redis.call()" 0 Now the explicit check for at least one argument prevents the problem. This commit fixes issue #655. --- src/scripting.c | 7 +++++++ tests/unit/scripting.tcl | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/scripting.c b/src/scripting.c index 8c89c923..b1cbc6ff 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -167,6 +167,13 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { redisClient *c = server.lua_client; sds reply; + /* Require at least one argument */ + if (argc == 0) { + luaPushError(lua, + "Please specify at least one argument for redis.call()"); + return 1; + } + /* Build the arguments vector */ argv = zmalloc(sizeof(robj*)*argc); for (j = 0; j < argc; j++) { diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index ec6e5c2a..6d60e419 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -145,6 +145,12 @@ start_server {tags {"scripting"}} { set e } {*not allowed after*} + test {EVAL - No arguments to redis.call/pcall is considered an error} { + set e {} + catch {r eval {return redis.call()} 0} e + set e + } {*one argument*} + test {EVAL - redis.call variant raises a Lua error on Redis cmd error (1)} { set e {} catch { -- 2.45.2