From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from camel.birch.relay.mailchannels.net (camel.birch.relay.mailchannels.net [23.83.209.29]) by sourceware.org (Postfix) with ESMTPS id 2564F3894410 for ; Mon, 19 Jul 2021 02:42:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2564F3894410 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 1324A121278; Mon, 19 Jul 2021 02:42:21 +0000 (UTC) Received: from pdx1-sub0-mail-a83.g.dreamhost.com (100-96-16-89.trex.outbound.svc.cluster.local [100.96.16.89]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 33592121DC5; Mon, 19 Jul 2021 02:42:20 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a83.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.16.89 (trex/6.3.3); Mon, 19 Jul 2021 02:42:21 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Suffer-Trail: 584be57954a9ce50_1626662540899_4190443250 X-MC-Loop-Signature: 1626662540899:2001276344 X-MC-Ingress-Time: 1626662540898 Received: from pdx1-sub0-mail-a83.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a83.g.dreamhost.com (Postfix) with ESMTP id EF5977F17F; Sun, 18 Jul 2021 19:42:19 -0700 (PDT) Received: from rhbox.intra.reserved-bit.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a83.g.dreamhost.com (Postfix) with ESMTPSA id 173A97E5F6; Sun, 18 Jul 2021 19:42:17 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a83 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: carlos@redhat.com, dj@redhat.com, fweimer@redhat.com Subject: [PATCH v9 10/10] mcheck Fix malloc_usable_size [BZ #22057] Date: Mon, 19 Jul 2021 08:11:34 +0530 Message-Id: <20210719024134.155398-11-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719024134.155398-1-siddhesh@sourceware.org> References: <20210719024134.155398-1-siddhesh@sourceware.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3494.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jul 2021 02:42:23 -0000 Interpose malloc_usable_size to return the correct mcheck value for malloc_usable_size. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- malloc/Makefile | 4 +--- malloc/malloc-debug.c | 8 ++++++-- malloc/mcheck-impl.c | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/malloc/Makefile b/malloc/Makefile index 4099d63a2a..6dc3fce3da 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -83,7 +83,7 @@ ifeq ($(have-GLIBC_2.23)$(build-shared),yesyes) # the tests expect specific internal behavior that is changed due to lin= king to # libmcheck.a. tests-exclude-mcheck =3D tst-mallocstate \ - tst-safe-linking tst-malloc-usable \ + tst-safe-linking \ tst-malloc-backtrace \ tst-malloc-fork-deadlock \ tst-malloc-stats-cancellation \ @@ -92,8 +92,6 @@ tests-exclude-mcheck =3D tst-mallocstate \ tst-malloc-thread-fail \ tst-malloc-usable-tunables \ tst-malloc_info \ - tst-pvalloc-fortify \ - tst-reallocarray \ tst-compathooks-off tst-compathooks-on =20 tests-mcheck =3D $(filter-out $(tests-exclude-mcheck), $(tests)) diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c index 41cadc31d7..044dd2bf55 100644 --- a/malloc/malloc-debug.c +++ b/malloc/malloc-debug.c @@ -370,8 +370,12 @@ strong_alias (__debug_calloc, calloc) size_t malloc_usable_size (void *mem) { - return (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK) - ? malloc_check_get_size (mem) : musable (mem)); + if (__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK)) + return mcheck_usable_size (mem); + if (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)) + return malloc_check_get_size (mem); + + return musable (mem); } =20 #define LIBC_SYMBOL(sym) libc_ ## sym diff --git a/malloc/mcheck-impl.c b/malloc/mcheck-impl.c index 8857e6b179..6597a290a6 100644 --- a/malloc/mcheck-impl.c +++ b/malloc/mcheck-impl.c @@ -404,3 +404,9 @@ __mcheck_initialize (void (*func) (enum mcheck_status= ), bool in_pedantic) pedantic =3D in_pedantic; return 0; } + +static int +mcheck_usable_size (struct hdr *h) +{ + return (h - 1)->size; +} --=20 2.31.1