diff mbox series

malloc: Replace shell/Perl gate in mtrace

Message ID 87bk3wj5rq.fsf@oldenburg.str.redhat.com
State New
Headers show
Series malloc: Replace shell/Perl gate in mtrace | expand

Commit Message

Florian Weimer June 20, 2024, 9:57 a.m. UTC
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

Comments

Andreas Schwab June 20, 2024, 10:32 a.m. UTC | #1
$ malloc/mtrace 
Can't locate malloc/mtrace in @INC (@INC contains: /usr/lib/perl5/site_perl/5.26.1/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.26.1 /usr/lib/perl5/vendor_perl/5.26.1/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.26.1 /usr/lib/perl5/5.26.1/x86_64-linux-thread-multi /usr/lib/perl5/5.26.1 /usr/lib/perl5/site_perl) at -e line 1.
diff mbox series

Patch

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.