summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorGuy Benoish <guy.benoish@redislabs.com>2020-01-30 18:14:45 +0530
committerantirez <antirez@gmail.com>2020-02-04 10:23:48 +0100
commit6fe55c2f299bbb306533af39cb28346bf5d473d3 (patch)
tree501eab21125fb0bf2d04fb6e60c1e4cccbc8cb95 /tests/modules
parentbbce3ba974d2f29240c569a7b30aaec14eba3e2b (diff)
downloadredis-6fe55c2f299bbb306533af39cb28346bf5d473d3.tar.gz
ld2string should fail if string contains \0 in the middle
This bug affected RM_StringToLongDouble and HINCRBYFLOAT. I added tests for both cases. Main changes: 1. Fixed string2ld to fail if string contains \0 in the middle 2. Use string2ld in getLongDoubleFromObject - No point of having duplicated code here The two changes above broke RM_SaveLongDouble/RM_LoadLongDouble because the long double string was saved with length+1 (An innocent mistake, but it's actually a bug - The length passed to RM_SaveLongDouble should not include the last \0).
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/misc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/modules/misc.c b/tests/modules/misc.c
index b5a032f60..41bec06ed 100644
--- a/tests/modules/misc.c
+++ b/tests/modules/misc.c
@@ -74,6 +74,15 @@ int test_ld_conv(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_ReplyWithError(ctx, err);
goto final;
}
+ /* Make sure we can't convert a string that has \0 in it */
+ char buf[4] = "123";
+ buf[1] = '\0';
+ RedisModuleString *s3 = RedisModule_CreateString(ctx, buf, 3);
+ long double ld3;
+ if (RedisModule_StringToLongDouble(s3, &ld3) == REDISMODULE_OK) {
+ RedisModule_ReplyWithError(ctx, "Invalid string successfully converted to long double");
+ goto final;
+ }
RedisModule_ReplyWithLongDouble(ctx, ld2);
final:
RedisModule_FreeString(ctx, s1);