From patchwork Fri Jul 7 18:48:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 72330 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 37ED93838364 for ; Fri, 7 Jul 2023 18:50:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37ED93838364 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688755835; bh=CGbXqajUoi4nwEN9bp2uQEXbVXNXpmaFFl9HaC0qXOE=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Ime7PicRwUpIwcJNY/qUYHLEuxbXXiRJBzxeannYjRc35DGJvsZuzRiXjzRSWwuZZ 6woZepzII5yUZcUhVdmp7VWIQ/86QllHGc6KpXbVMwm99LNln7esZ+GhJC0X8lae2D wP5wtIJhxjDp7REXkI6N4os/QoKDJYukKn6XxszI= 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 8871D3848174 for ; Fri, 7 Jul 2023 18:48:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8871D3848174 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-600-j6t9AIWXNiub1f6ieSYB9Q-1; Fri, 07 Jul 2023 14:48:09 -0400 X-MC-Unique: j6t9AIWXNiub1f6ieSYB9Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 076E83C11A18 for ; Fri, 7 Jul 2023 18:48:09 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BFB3492B01 for ; Fri, 7 Jul 2023 18:48:08 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH v2 08/32] elf: Eliminate alloca in open_verify In-Reply-To: Message-ID: References: X-From-Line: fa145fab21e060c011fed2e3ad31728777f67537 Mon Sep 17 00:00:00 2001 Date: Fri, 07 Jul 2023 20:48:06 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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" With the two-stage approach for exception handling, the name can be freed after it has been copied into the exception, but before it is raised. --- elf/dl-load.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index ff721fe5d2..fda0fe8000 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1636,15 +1636,13 @@ open_verify (const char *name, int fd, errval = errno; errstring = (errval == 0 ? N_("file too short") : N_("cannot read file data")); - lose: + lose:; + struct dl_exception exception; + _dl_exception_create (&exception, name, errstring); if (free_name) - { - char *realname = (char *) name; - name = strdupa (realname); - free (realname); - } + free ((char *) name); __close_nocancel (fd); - _dl_signal_error (errval, name, NULL, errstring); + _dl_signal_exception (errval, &exception, NULL); } /* See whether the ELF header is what we expect. */