From patchwork Thu Dec 7 10:31:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 81636 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 5DD91386182A for ; Thu, 7 Dec 2023 10:32:21 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 2416E385DC11 for ; Thu, 7 Dec 2023 10:31:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2416E385DC11 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2416E385DC11 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945102; cv=none; b=gwNyT2NFocUT7T1IIK6PIpyl8bsc73oEIN8PaULnfHLmnQK/Y+rj07o7BQRIcgrpR+eJ+/Jjrmf5vQZmZ4133DLsjPYMbAQtH3LSnljePxwTkSjywn5rJBkh76+e7MPfkPtIYcBpGiA5SRPUOPJFFwzSyTu3fxDMbWCbln6iSEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701945102; c=relaxed/simple; bh=Z+Ytr7PgbbnZhfqj2WX0GNZ4yYF++v610zPxqbLdQ10=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=LY1hIkwF+bj5iwFOqwO9uCPoCQ9SUUzoKkIOS5umQ/2jeDE39SvtEdTtaRhMIgx/gQFMPSqvRR0L7eQEJU2sbUUbfdgl4meqTMQTldFv1ellB5TDJFDumBKf/RUqo7jNoT4mSsI2s/6Ycrp4HycZZFegTRJwP2ERsBKr2tlLSAI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701945100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JaJrrfP1GCmhjiEQ8s2peGliHKonenwMV0SZlUhGER8=; b=APUA4XGz8ek7aQItl4YQslTRH2DHY6YiO7brBUY3emt3wIerv1r2gGK7OFD+fe/cc0m2FR ASh7AzmOFz2X/6+snLHXprBAugIZMYWAXi658NDjLk+i3uibrHNeY78RDTZFjRMDK8FvgV 5L32IE013wp8rwrqV3a/k6NNZJhDiTM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-HJkVXRuWMnePm1T5Brv28w-1; Thu, 07 Dec 2023 05:31:39 -0500 X-MC-Unique: HJkVXRuWMnePm1T5Brv28w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0A69185A786 for ; Thu, 7 Dec 2023 10:31:38 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.131]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 463FEC185A0 for ; Thu, 7 Dec 2023 10:31:38 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v3 08/32] elf: Eliminate alloca in open_verify In-Reply-To: Message-ID: <68d85e17f654a9524cbb02838cd74bddb0826388.1701944612.git.fweimer@redhat.com> References: X-From-Line: 68d85e17f654a9524cbb02838cd74bddb0826388 Mon Sep 17 00:00:00 2001 Date: Thu, 07 Dec 2023 11:31:36 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org 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 2084366663..d355de036a 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. */