Skip to content

Commit 6dc33bd

Browse files
rdevshpthestinger
authored andcommitted
h_malloc_object_size: fix unsigned underflow when p points to canary
1 parent 57db7cc commit 6dc33bd

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

h_malloc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,13 @@ EXPORT size_t h_malloc_object_size(const void *p) {
18611861
thread_seal_metadata();
18621862

18631863
size_t size = slab_usable_size(p);
1864-
return size ? size - canary_size - offset : 0;
1864+
size_t usable = size ? size - canary_size : 0;
1865+
1866+
if (unlikely(offset > usable)) {
1867+
fatal_error("invalid malloc_object_size (canary)");
1868+
}
1869+
1870+
return usable - offset;
18651871
}
18661872

18671873
if (unlikely(slab_region_end == NULL)) {

0 commit comments

Comments
 (0)