!579 [sync] PR-577: malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]

From: @openeuler-sync-bot 
Reviewed-by: @yang_yanchao 
Signed-off-by: @yang_yanchao
This commit is contained in:
openeuler-ci-bot 2023-04-14 16:57:36 +00:00 committed by Gitee
commit 9c979aff1f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 94 additions and 1 deletions

View File

@ -66,7 +66,7 @@
##############################################################################
Name: glibc
Version: 2.34
Release: 116
Release: 117
Summary: The GNU libc libraries
License: %{all_license}
URL: http://www.gnu.org/software/glibc/
@ -255,6 +255,7 @@ Patch167: backport-posix-Fix-system-blocks-SIGCHLD-erroneously-BZ-30163.patch
Patch168: backport-nscd-Fix-netlink-cache-invalidation-if-epoll-is-used.patch
Patch169: backport-nss_dns-In-gaih_getanswer_slice-skip-strange-aliases-bug-12154.patch
Patch170: backport-sunrpc-Suppress-GCC-Os-warning-on-user2netname.patch
Patch171: malloc-Fix-Wuse-after-free-warning-in-tst-mallocalig.patch
Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch
Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch
@ -1461,6 +1462,9 @@ fi
%endif
%changelog
* Thu Apr 13 2023 Qingqing Li <liqingqing3@huawei.com> - 2.34-117
- malloc: Fix -Wuse-after-free warning in tst-mallocalign1 [BZ #26779]
* Tue Apr 11 2023 zhanghao <zhanghao383@huawei.com> - 2.34-116
- nscd: Fix netlink cache invalidation if epoll is used [BZ #29415]
- nss_dns: In gaih_getanswer_slice, skip strange aliases (bug 12154)

View File

@ -0,0 +1,89 @@
From 6484ae5b8c4d4314f748e4d3c9a9baa5385e57c5 Mon Sep 17 00:00:00 2001
From: Carlos O'Donell <carlos@redhat.com>
Date: Fri, 28 Jan 2022 15:14:29 -0500
Subject: [PATCH] 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)
---
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 294e821afe..3e09ff30c4 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.33.0