Skip to content

Commit cb5babd

Browse files
committed
fix memset overflow in oldmalloc race fix overhaul
commit 3e16313 introduced this bug by making the copy case reachable with n (new size) smaller than n0 (original size). this was left as the only way of shrinking an allocation because it reduces fragmentation if a free chunk of the appropriate size is available. when that's not the case, another approach may be better, but any such improvement would be independent of fixing this bug.
1 parent 4bd22b8 commit cb5babd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/malloc/oldmalloc/malloc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void *realloc(void *p, size_t n)
409409
new = malloc(n-OVERHEAD);
410410
if (!new) return 0;
411411
copy_free_ret:
412-
memcpy(new, p, n0-OVERHEAD);
412+
memcpy(new, p, (n<n0 ? n : n0) - OVERHEAD);
413413
free(CHUNK_TO_MEM(self));
414414
return new;
415415
}

0 commit comments

Comments
 (0)