Skip to content

Commit

Permalink
Fix usage of RedisModule_HashGet in raw::hash_get and RedisModule_Has…
Browse files Browse the repository at this point in the history
…hSet in raw::hash_set (#99)

The Rust value "0" was being used as the terminating null pointer signalling the end of
the variadic arguments. Unfortunately the type of this expression is i32, which creates
a "read-past-the-end" condition in the calling C code. For calls to RedisModule_HashGet
with a single argument this seems to usually work correctly, but trying to do the with
2 or more fields crashes with a segmentation fault.
  • Loading branch information
slavak authored Sep 29, 2020
1 parent b23a5a5 commit 751bbd1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub fn hash_get(key: *mut RedisModuleKey, field: &str) -> *mut RedisModuleString
REDISMODULE_HASH_CFIELDS as i32,
CString::new(field).unwrap().as_ptr(),
&res,
0,
ptr::null::<c_char>(),
);
}
res
Expand All @@ -253,7 +253,7 @@ pub fn hash_set(key: *mut RedisModuleKey, field: &str, value: *mut RedisModuleSt
REDISMODULE_HASH_CFIELDS as i32,
CString::new(field).unwrap().as_ptr(),
value,
0,
ptr::null::<c_char>(),
)
.into()
}
Expand Down

0 comments on commit 751bbd1

Please sign in to comment.