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;
}
+10
View File
@@ -73,6 +73,16 @@ class TestGlobalStateStore(unittest.TestCase):
self.redis.execute_command("RAY.OBJECT_TABLE_ADD", "object_id1", 1, "hash1", "manager_id2")
response = self.redis.execute_command("RAY.OBJECT_TABLE_LOOKUP", "object_id1")
self.assertEqual(set(response), {b"manager_id1", b"manager_id2"})
# Check that we properly handle NULL characters. In the past, NULL
# characters were handled improperly causing a "hash mismatch" error if two
# object IDs that agreed up to the NULL character were inserted with
# different hashes.
self.redis.execute_command("RAY.OBJECT_TABLE_ADD", "\x00object_id3", 1, "hash1", "manager_id1")
self.redis.execute_command("RAY.OBJECT_TABLE_ADD", "\x00object_id4", 1, "hash2", "manager_id1")
# Check that NULL characters in the hash are handled properly.
self.redis.execute_command("RAY.OBJECT_TABLE_ADD", "object_id3", 1, "\x00hash1", "manager_id1")
with self.assertRaises(redis.ResponseError):
self.redis.execute_command("RAY.OBJECT_TABLE_ADD", "object_id3", 1, "\x00hash2", "manager_id1")
def testObjectTableSubscribe(self):
p = self.redis.pubsub()