diff options
author | Matt Stancliff <matt@genges.com> | 2014-06-10 14:21:37 -0400 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-06-11 10:14:26 +0200 |
commit | ba76daa42eea52c2c3a55cfdd40cf3d0b6e968d0 (patch) | |
tree | 09e21d3f9a4d06d410fd7d3b0d4b502eab0207c2 | |
parent | 8f774ee7ca1b6214391d7106112d63656236b200 (diff) | |
download | redis-ba76daa42eea52c2c3a55cfdd40cf3d0b6e968d0.tar.gz |
Scripting: Fix regression from #1118
The new check-for-number behavior of Lua arguments broke
users who use large strings of just integers.
The Lua number check would convert the string to a number, but
that breaks user data because
Lua numbers have limited precision compared to an arbitrarily
precise number wrapped in a string.
Regression fixed and new test added.
Fixes #1118 again.
-rw-r--r-- | src/scripting.c | 7 | ||||
-rw-r--r-- | tests/unit/scripting.tcl | 7 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/scripting.c b/src/scripting.c index 0f258ee11..0b6d848ec 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -200,6 +200,11 @@ void luaSortArray(lua_State *lua) { lua_pop(lua,1); /* Stack: array (sorted) */ } +int luaReallyIsString(lua_State *L, int index) { + int t = lua_type(L, index); + return t == LUA_TSTRING; +} + #define LUA_CMD_OBJCACHE_SIZE 32 #define LUA_CMD_OBJCACHE_MAX_LEN 64 int luaRedisGenericCommand(lua_State *lua, int raise_error) { @@ -234,7 +239,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { size_t obj_len; char dbuf[64]; - if (lua_isnumber(lua,j+1)) { + if (!luaReallyIsString(lua, j+1) && lua_isnumber(lua, j+1)) { /* We can't use lua_tolstring() for number -> string conversion * since Lua uses a format specifier that loses precision. */ lua_Number num = lua_tonumber(lua,j+1); diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index d7b6d2ca0..2c4171aeb 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -347,6 +347,13 @@ start_server {tags {"scripting"}} { return redis.call("get","foo") } 0 } {9007199254740991} + + test {String containing number precision test (regression of issue #1118)} { + r eval { + redis.call("set", "key", "12039611435714932082") + return redis.call("get", "key") + } 0 + } {12039611435714932082} } # Start a new server since the last test in this stanza will kill the |