forked from rpms/glibc
ad85e10075
Upstream commit: commit 6484ae5b8c4d4314f748e4d3c9a9baa5385e57c5 - malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779] - s_sincosf.h: Change pio4 type to float [BZ #28713] - math: Properly cast X_TLOSS to float [BZ #28713] - Regenerate ulps on x86_64 with GCC 12 - Avoid -Wuse-after-free in tests [BZ #26779]. - Fix build of nptl/tst-thread_local1.cc with GCC 12 - Fix stdio-common tests for GCC 12 -Waddress - Fix stdlib/tst-setcontext.c for GCC 12 -Warray-compare - resolv: Avoid GCC 12 false positive warning [BZ #28439]. - intl: Avoid -Wuse-after-free [BZ #26779] - elf: Drop elf/tls-macros.h in favor of __thread and tls_model attributes [BZ #28152] [BZ #28205] - time: Set daylight to 1 for matching DST/offset change (RHBZ#2155352) - elf/tst-tlsopt-powerpc fails when compiled with -mcpu=power10 (BZ# 29776) - time: Use 64 bit time on tzfile - nscd: Use 64 bit time_t on libc nscd routines (BZ# 29402) - nis: Build libnsl with 64 bit time_t - Use LFS and 64 bit time for installed programs (BZ #15333) Resolves: #2155352 Related: #2160734
84 lines
2.0 KiB
Diff
84 lines
2.0 KiB
Diff
commit 6484ae5b8c4d4314f748e4d3c9a9baa5385e57c5
|
|
Author: Carlos O'Donell <carlos@redhat.com>
|
|
Date: Fri Jan 28 15:14:29 2022 -0500
|
|
|
|
malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
|
|
|
|
The test leaks bits from the freed pointer via the return value
|
|
in ret, and the compiler correctly identifies this issue.
|
|
We switch the test to use TEST_VERIFY and terminate the test
|
|
if any of the pointers return an unexpected alignment.
|
|
|
|
This fixes another -Wuse-after-free error when compiling glibc
|
|
with gcc 12.
|
|
|
|
Tested on x86_64 and i686 without regression.
|
|
|
|
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
(cherry picked from commit 3a7bed5f5a527dbd87412551f41e42e63aeef07a)
|
|
|
|
diff --git a/malloc/tst-mallocalign1.c b/malloc/tst-mallocalign1.c
|
|
index 294e821afebd25ac..3e09ff30c4aa9f91 100644
|
|
--- a/malloc/tst-mallocalign1.c
|
|
+++ b/malloc/tst-mallocalign1.c
|
|
@@ -20,6 +20,7 @@
|
|
#include <stdlib.h>
|
|
#include <inttypes.h>
|
|
#include <malloc-size.h>
|
|
+#include <support/check.h>
|
|
|
|
static void *
|
|
test (size_t s)
|
|
@@ -31,41 +32,42 @@ test (size_t s)
|
|
return p;
|
|
}
|
|
|
|
+#define ALIGNED(p) (((uintptr_t )p & MALLOC_ALIGN_MASK) == 0)
|
|
+
|
|
static int
|
|
do_test (void)
|
|
{
|
|
void *p;
|
|
- int ret = 0;
|
|
|
|
p = test (2);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
p = test (8);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
p = test (13);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
p = test (16);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
p = test (23);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
p = test (43);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
p = test (123);
|
|
- ret |= (uintptr_t) p & MALLOC_ALIGN_MASK;
|
|
+ TEST_VERIFY (ALIGNED (p));
|
|
free (p);
|
|
|
|
- return ret;
|
|
+ return 0;
|
|
}
|
|
|
|
#include <support/test-driver.c>
|