From patchwork Mon May 17 12:07:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 43436 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E1713835433; Mon, 17 May 2021 12:08:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [IPv6:2001:a60:0:28:0:1:25:1]) by sourceware.org (Postfix) with ESMTPS id 96E3C3860C37 for ; Mon, 17 May 2021 12:07:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 96E3C3860C37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=whitebox@nefkom.net Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4FkHvd3kd6z1sHpJ for ; Mon, 17 May 2021 14:07:57 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4FkHvd0n2Sz1qqkL for ; Mon, 17 May 2021 14:07:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 91W9QIpJqoY7 for ; Mon, 17 May 2021 14:07:56 +0200 (CEST) X-Auth-Info: D53GP5KAiualnaKSmTjufBRr5jK/MmfwFfvLVBCgIotDjr23L6ldORA8uKlhQaEt Received: from igel.home (ppp-46-244-160-196.dynamic.mnet-online.de [46.244.160.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA for ; Mon, 17 May 2021 14:07:56 +0200 (CEST) Received: by igel.home (Postfix, from userid 1000) id 04AB62C365A; Mon, 17 May 2021 14:07:55 +0200 (CEST) From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Missing ENOMEM in realloc_check wrapper (bug 27870) X-Yow: Finally, Zippy drives his 1958 RAMBLER METROPOLITAN into the faculty dining room. Date: Mon, 17 May 2021 14:07:55 +0200 Message-ID: <87v97h8sx0.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" When MALLOC_CHECK_ is non-zero, the realloc hook missed to set errno to ENOMEM when called with too big size. Run the test tst-malloc-too-large also with MALLOC_CHECK_=3 to catch that. Reviewed-by: DJ Delorie --- malloc/Makefile | 2 +- malloc/hooks.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/malloc/Makefile b/malloc/Makefile index afcd296ef6..857e2ebbd9 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -72,7 +72,7 @@ test-srcs = tst-mtrace # with MALLOC_CHECK_=3 because they expect a specific failure. tests-exclude-mcheck = tst-mcheck tst-malloc-usable \ tst-interpose-nothread tst-interpose-static-nothread \ - tst-interpose-static-thread tst-malloc-too-large \ + tst-interpose-static-thread \ tst-mxfast tst-safe-linking # Run all tests with MALLOC_CHECK_=3 diff --git a/malloc/hooks.c b/malloc/hooks.c index c91f9502ba..8080c3f40e 100644 --- a/malloc/hooks.c +++ b/malloc/hooks.c @@ -321,7 +321,10 @@ realloc_check (void *oldmem, size_t bytes, const void *caller) const INTERNAL_SIZE_T oldsize = chunksize (oldp); if (!checked_request2size (rb, &chnb)) - goto invert; + { + __set_errno (ENOMEM); + goto invert; + } __libc_lock_lock (main_arena.mutex);