* [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
@ 2022-01-31 5:21 Carlos O'Donell
2022-01-31 5:32 ` Siddhesh Poyarekar
2022-01-31 8:31 ` Andreas Schwab
0 siblings, 2 replies; 6+ messages in thread
From: Carlos O'Donell @ 2022-01-31 5:21 UTC (permalink / raw)
To: libc-alpha, joseph
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.
---
malloc/tst-mallocalign1.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/malloc/tst-mallocalign1.c b/malloc/tst-mallocalign1.c
index 8bfd50c468..3116748e7e 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>
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
2022-01-31 5:21 [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779] Carlos O'Donell
@ 2022-01-31 5:32 ` Siddhesh Poyarekar
2022-01-31 6:00 ` Carlos O'Donell
2022-01-31 8:31 ` Andreas Schwab
1 sibling, 1 reply; 6+ messages in thread
From: Siddhesh Poyarekar @ 2022-01-31 5:32 UTC (permalink / raw)
To: Carlos O'Donell, libc-alpha, joseph
On 31/01/2022 10:51, Carlos O'Donell via Libc-alpha wrote:
> 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.
LGTM.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
2022-01-31 5:32 ` Siddhesh Poyarekar
@ 2022-01-31 6:00 ` Carlos O'Donell
0 siblings, 0 replies; 6+ messages in thread
From: Carlos O'Donell @ 2022-01-31 6:00 UTC (permalink / raw)
To: Siddhesh Poyarekar, libc-alpha, joseph
On 1/31/22 00:32, Siddhesh Poyarekar wrote:
> On 31/01/2022 10:51, Carlos O'Donell via Libc-alpha wrote:
>> 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.
>
> LGTM.
>
> Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
>
Thanks. Pushed. That fixes the last gcc 12 issue I'm seeing on x86 for
the glibc 2.35 release.
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
2022-01-31 5:21 [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779] Carlos O'Donell
2022-01-31 5:32 ` Siddhesh Poyarekar
@ 2022-01-31 8:31 ` Andreas Schwab
2022-01-31 15:20 ` Carlos O'Donell
1 sibling, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2022-01-31 8:31 UTC (permalink / raw)
To: Carlos O'Donell via Libc-alpha; +Cc: joseph, Carlos O'Donell
On Jan 31 2022, Carlos O'Donell via Libc-alpha wrote:
> +#define ALIGNED(p) (((uintptr_t )p & MALLOC_ALIGN_MASK) == 0)
Wrong spacing.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
2022-01-31 8:31 ` Andreas Schwab
@ 2022-01-31 15:20 ` Carlos O'Donell
2022-02-01 17:08 ` Carlos O'Donell
0 siblings, 1 reply; 6+ messages in thread
From: Carlos O'Donell @ 2022-01-31 15:20 UTC (permalink / raw)
To: Andreas Schwab, Carlos O'Donell via Libc-alpha; +Cc: joseph
On 1/31/22 03:31, Andreas Schwab wrote:
> On Jan 31 2022, Carlos O'Donell via Libc-alpha wrote:
>
>> +#define ALIGNED(p) (((uintptr_t )p & MALLOC_ALIGN_MASK) == 0)
>
> Wrong spacing.
Good catch. Thanks.
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
2022-01-31 15:20 ` Carlos O'Donell
@ 2022-02-01 17:08 ` Carlos O'Donell
0 siblings, 0 replies; 6+ messages in thread
From: Carlos O'Donell @ 2022-02-01 17:08 UTC (permalink / raw)
To: Andreas Schwab, Carlos O'Donell via Libc-alpha; +Cc: joseph
On 1/31/22 10:20, Carlos O'Donell wrote:
> On 1/31/22 03:31, Andreas Schwab wrote:
>> On Jan 31 2022, Carlos O'Donell via Libc-alpha wrote:
>>
>>> +#define ALIGNED(p) (((uintptr_t )p & MALLOC_ALIGN_MASK) == 0)
>>
>> Wrong spacing.
>
> Good catch. Thanks.
>
Fixed and pushed as obvious fix.
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-01 17:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 5:21 [PATCH] malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779] Carlos O'Donell
2022-01-31 5:32 ` Siddhesh Poyarekar
2022-01-31 6:00 ` Carlos O'Donell
2022-01-31 8:31 ` Andreas Schwab
2022-01-31 15:20 ` Carlos O'Donell
2022-02-01 17:08 ` Carlos O'Donell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).