mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-10-01 01:36:01 -04:00
realloc: use copy_size to check for canaries
This avoids unnecessarily copying the canary when doing a realloc from a small size to a large size. It also avoids trying to copy a non-existent canary out of a zero-size allocation, which are memory protected.
This commit is contained in:
parent
37474e117c
commit
bc75c4db7b
@ -1474,7 +1474,7 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
||||
return NULL;
|
||||
}
|
||||
size_t copy_size = min(size, old_size);
|
||||
if (size > 0 && size <= max_slab_size_class) {
|
||||
if (copy_size > 0 && copy_size <= max_slab_size_class) {
|
||||
copy_size -= canary_size;
|
||||
}
|
||||
memcpy(new, old, copy_size);
|
||||
|
Loading…
Reference in New Issue
Block a user