mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 03:25:31 +03:00
alloc-util: don't use malloc_usable_size() to determine allocated size
This reverts commit d4b604baea
.
When realloc() is called, the extra memory between the originally
requested size and the end of malloc_usable_size() isn't copied. (at
least with the version of glibc that currently ships on Arch Linux)
As a result, some elements get lost and use uninitialized memory, most
commonly 0, and can lead to crashes.
fixes #12384
This commit is contained in:
parent
b9de47b97b
commit
fcc72fd0f1
@ -1,6 +1,5 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -65,7 +64,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
|
||||
return NULL;
|
||||
|
||||
*p = q;
|
||||
*allocated = _unlikely_(size == 0) ? newalloc : malloc_usable_size(q) / size;
|
||||
*allocated = newalloc;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user