From patchwork Thu Jun 20 09:57:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 92522 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 B001C3891C28 for ; Thu, 20 Jun 2024 09:59:51 +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 DDE6C3890438 for ; Thu, 20 Jun 2024 09:57:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDE6C3890438 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 DDE6C3890438 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=1718877461; cv=none; b=M9H+LzaNfsOqeEnzHpSPl8pHbFspRLQTHsi5mb8jOvmJ0d1C7szKRuTMcrRkYLS02gtwSi3F7vykUmN47gkn2O0D2BBwfDnigPaZUpXbjAifKRurY1h30BiqmVIBWvCRSd6uLGHvm84hnZa4BQ7cvsO5q9VKCjpeQiwWFZhKceE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718877461; c=relaxed/simple; bh=jPKg+vEyHQwBHJYyGchtrDVeF6EfzDbpLN/3t0t/0cM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZfnStsgN6dA93rltF7o148FY8mIUevjJAHWTDKGnZUmnAkn7iNea9BtYxtJCJkJTUu+rUkCvIF5iebe48OPfkWI0mfwB/neORlkfHiqAFwVTsriwtrzd4yB+OHW2Lk7AoQdX6jHprfbS/9oKXIpT7GB5gAq+8/91xucN7YekcTc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718877457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iL72I75nQqtgj1d+WyIbNrSg1BhOsWAKPqALazq4emI=; b=YPAvAVMwT6f9PuftpyokojEzKVUdMy+WRd0KsReEojF49xvQAqnWIdCbrkvQWULG1AthJH bUoRaEtysEHDGgi7s/oqPgyHu90gC4o+CEX6mMO/wMATREBu2pwmVIxNhKjRGB9xkQ5X16 uNgMaMHgUyxkYnN5+EHbWr5OHMg+Mt0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-EtNW5JpXM6O_3odOPzr5eA-1; Thu, 20 Jun 2024 05:57:34 -0400 X-MC-Unique: EtNW5JpXM6O_3odOPzr5eA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 687EB19560B8; Thu, 20 Jun 2024 09:57:33 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.21]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 57E67300022B; Thu, 20 Jun 2024 09:57:32 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Cc: Andreas Schwab Subject: [PATCH] malloc: Replace shell/Perl gate in mtrace Date: Thu, 20 Jun 2024 11:57:29 +0200 Message-ID: <87bk3wj5rq.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, 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 The previous version expanded $0 and $@ twice. The new version defines a q no-op shell command. The Perl syntax error is masked by the eval Perl function. The q { … } construct is executed by the shell without errors because the q shell function was defined, but treated as a non-expanding quoted string by Perl, effectively hiding its context from the Perl interpreter. As before the script is read by require instead of executed directly, to avoid infinite recursion because the #! line contains /bin/sh. --- malloc/mtrace.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) base-commit: 086910fc41655152812b515dc324d2ac0dc36e67 diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl index dc6085820e..a6e2ca7589 100644 --- a/malloc/mtrace.pl +++ b/malloc/mtrace.pl @@ -1,6 +1,11 @@ #! /bin/sh -eval exec "perl -e 'shift; \$progname=shift; shift; require \$progname'" . "$0" . "$@" - if 0; +eval "q () { + : +}"; +q { + exec perl -e '$progname=shift; require $progname' "$0" "$@" +} +; # Copyright (C) 1997-2024 Free Software Foundation, Inc. # This file is part of the GNU C Library. # Based on the mtrace.awk script.