]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
malloc: check "negative" tcache_key values by hand
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 9 Sep 2025 21:03:26 +0000 (23:03 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Tue, 9 Sep 2025 21:05:00 +0000 (23:05 +0200)
instead of undefined cases from casting uintptr_t into intptr_t.

malloc/malloc.c

index 444dc618257d87c0373388c97f5f164164cc26ad..18ef6b5cb81108624781ebb5d3ce59e516f6f8f1 100644 (file)
@@ -3150,7 +3150,8 @@ tcache_key_initialize (void)
   int minimum_bits = __WORDSIZE / 4;
   int maximum_bits = __WORDSIZE - minimum_bits;
 
-  while (labs ((intptr_t) tcache_key) <= 0x1000000
+  while (tcache_key <= 0x1000000
+      || tcache_key >= ((uintptr_t) ULONG_MAX) - 0x1000000
       || stdc_count_ones (tcache_key) < minimum_bits
       || stdc_count_ones (tcache_key) > maximum_bits)
     {