From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1011 invoked by alias); 28 Nov 2017 14:10:16 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 922 invoked by uid 89); 28 Nov 2017 14:10:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=victim X-Spam-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: homiemail-a52.g.dreamhost.com Received: from sub5.mail.dreamhost.com (HELO homiemail-a52.g.dreamhost.com) (208.113.200.129) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Nov 2017 14:10:10 +0000 Received: from homiemail-a52.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a52.g.dreamhost.com (Postfix) with ESMTP id A193E600063B; Tue, 28 Nov 2017 06:10:09 -0800 (PST) Received: from devel.in.reserved-bit.com (unknown [202.189.238.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by homiemail-a52.g.dreamhost.com (Postfix) with ESMTPSA id 7A1CA6000630; Tue, 28 Nov 2017 06:10:08 -0800 (PST) From: Siddhesh Poyarekar To: libc-stable@sourceware.org Cc: Florian Weimer Subject: [PATCH 04/10] malloc: Change top_check return type to void Date: Sun, 01 Jan 2017 00:00:00 -0000 Message-Id: <1511878186-31499-5-git-send-email-siddhesh@sourceware.org> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1511878186-31499-1-git-send-email-siddhesh@sourceware.org> References: <1511878186-31499-1-git-send-email-siddhesh@sourceware.org> X-SW-Source: 2017-11/txt/msg00037.txt.bz2 From: Florian Weimer After commit ec2c1fcefb200c6cb7e09553f3c6af8815013d83, (malloc: Abort on heap corruption, without a backtrace), the function always returns 0. (cherry-picked from 5129873a8e913e207e5f7b4b521c72f41a1bbf6d) --- ChangeLog | 7 +++++++ malloc/hooks.c | 26 ++++++++++++-------------- malloc/malloc.c | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 577643c..519db42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2017-08-31 Florian Weimer + + * malloc/malloc.c (top_check): Change return type to void. Remove + internal_function. + * malloc/hooks.c (top_check): Likewise. + (malloc_check, realloc_check, memalign_check): Adjust. + 2017-08-30 Florian Weimer * malloc/malloc.c (ARENA_CORRUPTION_BIT, arena_is_corrupt) diff --git a/malloc/hooks.c b/malloc/hooks.c index dcd311e..4398c0a 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -228,8 +228,7 @@ mem2chunk_check (void *mem, unsigned char **magic_p) } /* Check for corruption of the top chunk. */ -static int -internal_function +static void top_check (void) { mchunkptr t = top (&main_arena); @@ -240,7 +239,7 @@ top_check (void) prev_inuse (t) && (!contiguous (&main_arena) || (char *) t + chunksize (t) == mp_.sbrk_base + main_arena.system_mem))) - return 0; + return; malloc_printerr ("malloc: top chunk is corrupt"); } @@ -257,7 +256,8 @@ malloc_check (size_t sz, const void *caller) } __libc_lock_lock (main_arena.mutex); - victim = (top_check () >= 0) ? _int_malloc (&main_arena, sz + 1) : NULL; + top_check (); + victim = _int_malloc (&main_arena, sz + 1); __libc_lock_unlock (main_arena.mutex); return mem2mem_check (victim, sz); } @@ -329,8 +329,8 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) else { /* Must alloc, copy, free. */ - if (top_check () >= 0) - newmem = _int_malloc (&main_arena, bytes + 1); + top_check (); + newmem = _int_malloc (&main_arena, bytes + 1); if (newmem) { memcpy (newmem, oldmem, oldsize - 2 * SIZE_SZ); @@ -341,12 +341,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) } else { - if (top_check () >= 0) - { - INTERNAL_SIZE_T nb; - checked_request2size (bytes + 1, nb); - newmem = _int_realloc (&main_arena, oldp, oldsize, nb); - } + top_check (); + INTERNAL_SIZE_T nb; + checked_request2size (bytes + 1, nb); + newmem = _int_realloc (&main_arena, oldp, oldsize, nb); } /* mem2chunk_check changed the magic byte in the old chunk. @@ -396,8 +394,8 @@ memalign_check (size_t alignment, size_t bytes, const void *caller) } __libc_lock_lock (main_arena.mutex); - mem = (top_check () >= 0) ? _int_memalign (&main_arena, alignment, bytes + 1) : - NULL; + top_check (); + mem = _int_memalign (&main_arena, alignment, bytes + 1); __libc_lock_unlock (main_arena.mutex); return mem2mem_check (mem, bytes); } diff --git a/malloc/malloc.c b/malloc/malloc.c index 65deb2f..417ffbb 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1022,7 +1022,7 @@ static void* _mid_memalign(size_t, size_t, void *); static void malloc_printerr(const char *str) __attribute__ ((noreturn)); static void* internal_function mem2mem_check(void *p, size_t sz); -static int internal_function top_check(void); +static void top_check (void); static void internal_function munmap_chunk(mchunkptr p); #if HAVE_MREMAP static mchunkptr internal_function mremap_chunk(mchunkptr p, size_t new_size); -- 2.7.5