Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/t_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ bool hashTypeHasStringRef(robj *o, sds field) {
if (objectGetEncoding(o) == OBJ_ENCODING_LISTPACK) return false;
hashtable *ht = objectGetVal(o);
void **entry_ref = hashtableFindRef(ht, field);
if (!entry_ref) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crash path still has no regression coverage: tests/unit/moduleapi/hash_stringref.tcl only queries the existing field f. After hash.set_stringref has converted k to a hashtable, add assert_equal "0" [r hash.has_stringref k missing]; that specifically exercises hashtableFindRef() returning NULL and protects this guard.

return (entryHasStringRef(*entry_ref));
}

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/moduleapi/hash_stringref.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ start_server {tags {"modules"}} {
assert_equal "1" [r hash.has_stringref k f]
}

test {Module hash has_stringref on non-existent field} {
r del k
r hset k f hello1
# Setting a stringref converts the hash to the hashtable encoding, which
# is the only encoding that looks the field up in the hashtable.
r hash.set_stringref k f hello1
assert_encoding hashtable k
# Missing field must return 0 rather than dereferencing a NULL entry.
assert_equal "0" [r hash.has_stringref k nonexistent]
}

test "Unload the module - hash" {
assert_equal {OK} [r module unload hash.stringref]
}
Expand Down
Loading