summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Barany <aaron.barany@here.com>2019-04-29 15:00:30 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-04-30 08:20:59 +0200
commitfcc72fd0f103c95810f0335684d0bf6f6ed6481b (patch)
tree3daef1618d715553b74563feecbeb6cd3cb8416b
parentb9de47b97b0462b97376a58757f2361bbaab541b (diff)
downloadsystemd-fcc72fd0f103c95810f0335684d0bf6f6ed6481b.tar.gz
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
-rw-r--r--src/basic/alloc-util.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c
index 1e4ee722f2..f4bd33f4e0 100644
--- a/src/basic/alloc-util.c
+++ b/src/basic/alloc-util.c
@@ -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;
}