Open avrs-admin opened 2 years ago
Petteri Aimonen
This got triggered by nanopb fuzz tests; I'm adding a workaround on my library side as this would otherwise have potential security implications. It would be great if this could eventually be fixed on avr-libc side.
I think the suggested patch does not address the case of len == 0, which should be equivalent to free(ptr). I've attached a patch that handles that also.
Petteri Aimonen
Related other bugs: #40535, #32702
Sun 04 Mar 2018 11:19:44 PM CET
The realloc() function does not respect the freelist size when resizing an allocation down to 0 or 1 bytes. If this allocation is then deallocated with free(), a freelist entry is placed in its slot that can partially overwrite an adjacent allocation, leading to irrecoverable memory corruption. The following code can reproduce the corruption:
malloc() handles this issue with a minimum allocation size, so that requested allocations of 0, 1, or 2 bytes all take the same storage. The same technique can be used here to prevent problems, as shown in the attached patch.
file #43463: realloc_small_size.patch file #48143: avr-libc-realloc-small-len-values.patch
This issue was migrated from https://savannah.nongnu.org/bugs/?53284