Fix redzone setting and checking

This commit is contained in:
Yinan Zhang 2019-07-03 16:48:47 -07:00 committed by David Goldblatt
parent 40a3435b8d
commit 7720b6e385

View File

@ -9,7 +9,7 @@ JEMALLOC_ALWAYS_INLINE void
safety_check_set_redzone(void *ptr, size_t usize, size_t bumped_usize) { safety_check_set_redzone(void *ptr, size_t usize, size_t bumped_usize) {
assert(usize < bumped_usize); assert(usize < bumped_usize);
for (size_t i = usize; i < bumped_usize && i < usize + 32; ++i) { for (size_t i = usize; i < bumped_usize && i < usize + 32; ++i) {
*((unsigned char *)ptr + usize) = 0xBC; *((unsigned char *)ptr + i) = 0xBC;
} }
} }
@ -17,7 +17,7 @@ JEMALLOC_ALWAYS_INLINE void
safety_check_verify_redzone(const void *ptr, size_t usize, size_t bumped_usize) safety_check_verify_redzone(const void *ptr, size_t usize, size_t bumped_usize)
{ {
for (size_t i = usize; i < bumped_usize && i < usize + 32; ++i) { for (size_t i = usize; i < bumped_usize && i < usize + 32; ++i) {
if (unlikely(*((unsigned char *)ptr + usize) != 0xBC)) { if (unlikely(*((unsigned char *)ptr + i) != 0xBC)) {
safety_check_fail("Use after free error\n"); safety_check_fail("Use after free error\n");
} }
} }