From patchwork Thu Jul 21 10:34:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 56221 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 4BED73856DF5 for ; Thu, 21 Jul 2022 10:35:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BED73856DF5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658399701; bh=4o0akfEPB35iKCYw9i5Mumkf6jRH45ScOnU0iHhxSC0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=e9fLi++9lg/L7tfzHW2nDjSIDNUV1WRnHYmT/a1hygVz37lqS98x52pwh0Ieu5HvC v/wrg56/hK0EuSbaQYlLii04ATiSrQ7V33ZdoH8TFIXxNlO6QAktPIBVzRCo/lTAjy 47OlSneGDToJs06yYJxnylx9OqlzK6GjG3mOUiig= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2D7C938582A1 for ; Thu, 21 Jul 2022 10:34:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D7C938582A1 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-576-LodIy7cvOYC-yubGEOtJbQ-1; Thu, 21 Jul 2022 06:34:31 -0400 X-MC-Unique: LodIy7cvOYC-yubGEOtJbQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E48013801F53 for ; Thu, 21 Jul 2022 10:34:30 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.154]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6330618ECB for ; Thu, 21 Jul 2022 10:34:30 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Simplify implementation of __malloc_assert Date: Thu, 21 Jul 2022 12:34:28 +0200 Message-ID: <87a6924uvf.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It is prudent not to run too much code after detecting heap corruption, and __fxprintf is really complex. The line number and file name do not carry much information, so it is not included in the error message. (__libc_message only supports %s formatting.) The function name and assertion should provide some context. Tested on i686-linux-gnu and x86_64-linux-gnu. Also emulated the __libc_message call using GDB, and it produced the expected output. Thanks, Florian Reviewed-by: Siddhesh Poyarekar --- malloc/malloc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 12908b8f97..bd3c76ed31 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -292,19 +292,14 @@ # define __assert_fail(assertion, file, line, function) \ __malloc_assert(assertion, file, line, function) -extern const char *__progname; - -static void +_Noreturn static void __malloc_assert (const char *assertion, const char *file, unsigned int line, const char *function) { - (void) __fxprintf (NULL, "%s%s%s:%u: %s%sAssertion `%s' failed.\n", - __progname, __progname[0] ? ": " : "", - file, line, - function ? function : "", function ? ": " : "", - assertion); - fflush (stderr); - abort (); + __libc_message (do_abort, "\ +Fatal glibc error: malloc assertion failure in %s: %s\n", + function, assertion); + __builtin_unreachable (); } #endif #endif