1d4c55
From b9cde4e3aa1ff338da7064daf1386b2f4a7351ba Mon Sep 17 00:00:00 2001
1d4c55
From: DJ Delorie <dj@redhat.com>
1d4c55
Date: Sat, 4 Apr 2020 01:44:56 -0400
1d4c55
Subject: malloc: ensure set_max_fast never stores zero [BZ #25733]
1d4c55
1d4c55
The code for set_max_fast() stores an "impossibly small value"
1d4c55
instead of zero, when the parameter is zero.  However, for
1d4c55
small values of the parameter (ex: 1 or 2) the computation
1d4c55
results in a zero being stored anyway.
1d4c55
1d4c55
This patch checks for the parameter being small enough for the
1d4c55
computation to result in zero instead, so that a zero is never
1d4c55
stored.
1d4c55
1d4c55
key values which result in zero being stored:
1d4c55
1d4c55
x86-64:  1..7  (or other 64-bit)
1d4c55
i686:    1..11
1d4c55
armhfp:  1..3  (or other 32-bit)
1d4c55
1d4c55
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
1d4c55
1d4c55
diff --git a/malloc/malloc.c b/malloc/malloc.c
1d4c55
index 6acb5ad43a..ee87ddbbf9 100644
1d4c55
--- a/malloc/malloc.c
1d4c55
+++ b/malloc/malloc.c
1d4c55
@@ -1632,7 +1632,7 @@ static INTERNAL_SIZE_T global_max_fast;
1d4c55
  */
1d4c55
 
1d4c55
 #define set_max_fast(s) \
1d4c55
-  global_max_fast = (((s) == 0)						      \
1d4c55
+  global_max_fast = (((size_t) (s) <= MALLOC_ALIGN_MASK - SIZE_SZ)	\
1d4c55
                      ? MIN_CHUNK_SIZE / 2 : ((s + SIZE_SZ) & ~MALLOC_ALIGN_MASK))
1d4c55
 
1d4c55
 static inline INTERNAL_SIZE_T