From: Aaron Barany Date: Mon, 29 Apr 2019 22:00:30 +0000 (-0700) Subject: alloc-util: don't use malloc_usable_size() to determine allocated size X-Git-Tag: v243-rc1~499 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fcc72fd0f103c95810f0335684d0bf6f6ed6481b;p=thirdparty%2Fsystemd.git alloc-util: don't use malloc_usable_size() to determine allocated size This reverts commit d4b604baeadbb2498e4f2c3e260260eed210f5d6. 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 --- diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c index 1e4ee722f20..f4bd33f4e01 100644 --- a/src/basic/alloc-util.c +++ b/src/basic/alloc-util.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#include #include #include @@ -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; }