]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: ensure set_max_fast never stores zero [BZ #25733]
authorDJ Delorie <dj@redhat.com>
Sat, 4 Apr 2020 05:44:56 +0000 (01:44 -0400)
committerDJ Delorie <dj@redhat.com>
Mon, 6 Apr 2020 20:27:53 +0000 (16:27 -0400)
The code for set_max_fast() stores an "impossibly small value"
instead of zero, when the parameter is zero.  However, for
small values of the parameter (ex: 1 or 2) the computation
results in a zero being stored anyway.

This patch checks for the parameter being small enough for the
computation to result in zero instead, so that a zero is never
stored.

key values which result in zero being stored:

x86-64:  1..7  (or other 64-bit)
i686:    1..11
armhfp:  1..3  (or other 32-bit)

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
malloc/malloc.c

index 6acb5ad43aaa9e059e9c8f813bc082d7436e9982..ee87ddbbf9c3b8da9f0f6daa84b42b0a6a859fe0 100644 (file)
@@ -1632,7 +1632,7 @@ static INTERNAL_SIZE_T global_max_fast;
  */
 
 #define set_max_fast(s) \
-  global_max_fast = (((s) == 0)                                                      \
+  global_max_fast = (((size_t) (s) <= MALLOC_ALIGN_MASK - SIZE_SZ)     \
                      ? MIN_CHUNK_SIZE / 2 : ((s + SIZE_SZ) & ~MALLOC_ALIGN_MASK))
 
 static inline INTERNAL_SIZE_T