Fix improper handling of NULL characters when opening Redis keys. (#136)

* Fix improper handling of NULL characters when opening Redis keys.

* Add test.
This commit is contained in:
Robert Nishihara
2016-12-18 13:06:28 -08:00
committed by Philipp Moritz
parent a9e6a53360
commit c89bf4e5bc
2 changed files with 15 additions and 2 deletions
+5 -2
View File
@@ -35,8 +35,11 @@ RedisModuleString *CreatePrefixedString(RedisModuleCtx *ctx,
RedisModuleString *keyname) {
size_t length;
const char *value = RedisModule_StringPtrLen(keyname, &length);
RedisModuleString *prefixed_keyname = RedisModule_CreateStringPrintf(
ctx, "%s%*.*s", prefix, length, length, value);
RedisModuleString *prefixed_keyname =
RedisModule_CreateString(ctx, prefix, strlen(prefix));
/* Using RedisModule_CreateStringPrintf in the past did not handle NULL
* characters properly. */
RedisModule_StringAppendBuffer(ctx, prefixed_keyname, value, length);
return prefixed_keyname;
}