From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2206) id 919CE396DC36; Mon, 19 Jul 2021 17:48:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 919CE396DC36 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Siddhesh Poyarekar To: glibc-cvs@sourceware.org Subject: [glibc/siddhesh/malloc-hooks] mcheck Fix malloc_usable_size [BZ #22057] X-Act-Checkin: glibc X-Git-Author: Siddhesh Poyarekar X-Git-Refname: refs/heads/siddhesh/malloc-hooks X-Git-Oldrev: 37ab08a8bc891d05b4d5a9eeadc2e00b5b448698 X-Git-Newrev: bb441626aec1afedd1581d7dc4518a963593712f Message-Id: <20210719174832.919CE396DC36@sourceware.org> Date: Mon, 19 Jul 2021 17:48:32 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jul 2021 17:48:32 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bb441626aec1afedd1581d7dc4518a963593712f commit bb441626aec1afedd1581d7dc4518a963593712f Author: Siddhesh Poyarekar Date: Tue Jul 13 07:08:42 2021 +0530 mcheck Fix malloc_usable_size [BZ #22057] Interpose malloc_usable_size to return the correct mcheck value for malloc_usable_size. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell Diff: --- malloc/Makefile | 4 +--- malloc/malloc-debug.c | 2 ++ malloc/mcheck-impl.c | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/malloc/Makefile b/malloc/Makefile index a2b4383b68..48c6056fb3 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 linking to # libmcheck.a. tests-exclude-mcheck = 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 = tst-mallocstate \ tst-malloc-thread-fail \ tst-malloc-usable-tunables \ tst-malloc_info \ - tst-pvalloc-fortify \ - tst-reallocarray \ tst-compathooks-off tst-compathooks-on tests-mcheck = $(filter-out $(tests-exclude-mcheck), $(tests)) diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c index 34523b0cc3..9922ef5f25 100644 --- a/malloc/malloc-debug.c +++ b/malloc/malloc-debug.c @@ -399,6 +399,8 @@ strong_alias (__debug_calloc, calloc) size_t malloc_usable_size (void *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); 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 = in_pedantic; return 0; } + +static int +mcheck_usable_size (struct hdr *h) +{ + return (h - 1)->size; +}