diff options
author | antirez <antirez@gmail.com> | 2015-01-20 18:01:28 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-01-22 10:36:15 +0100 |
commit | a0ba7b3f00b91eec3a8a6ec3587166e29015a4b3 (patch) | |
tree | 2d0cba036f2b66d6e8f9c5f1c9472280337e9744 | |
parent | e7aa5fb5ef5e106895261b9a7fc6e65874e22d7e (diff) | |
download | redis-a0ba7b3f00b91eec3a8a6ec3587166e29015a4b3.tar.gz |
Panic on recursive calls to luaRedisGenericCommand().
Related to issue #2302.
-rw-r--r-- | src/scripting.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/scripting.c b/src/scripting.c index 7dbd5f74f..5a020a733 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -213,11 +213,22 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { static int argv_size = 0; static robj *cached_objects[LUA_CMD_OBJCACHE_SIZE]; static size_t cached_objects_len[LUA_CMD_OBJCACHE_SIZE]; + static int inuse = 0; /* Recursive calls detection. */ + + /* By using Lua debug hooks it is possible to trigger a recursive call + * to luaRedisGenericCommand(), which normally should never happen. + * To make this function reentrant is futile and makes it slower, but + * we should at least detect such a misuse, and abort. */ + if (inuse) { + redisPanic("luaRedisGenericCommand() recursive call detected. Are you doing funny stuff with Lua debug hooks?"); + } + inuse++; /* Require at least one argument */ if (argc == 0) { luaPushError(lua, "Please specify at least one argument for redis.call()"); + inuse--; return 1; } @@ -272,6 +283,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { } luaPushError(lua, "Lua redis() command arguments must be strings or integers"); + inuse--; return 1; } @@ -408,8 +420,10 @@ cleanup: * return the plain error. */ lua_pushstring(lua,"err"); lua_gettable(lua,-2); + inuse--; return lua_error(lua); } + inuse--; return 1; } |