From: Bruno Haible Date: Fri, 29 May 2026 13:55:27 +0000 (+0200) Subject: compile, depcomp, ylwrap: Fix quoting bug in 'trap' command. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb4ebe2f049f7169ee7671fccc487d095ee0ac0e;p=thirdparty%2Fautomake.git compile, depcomp, ylwrap: Fix quoting bug in 'trap' command. Reported by an AI tool in the name of MichaƂ Majchrowicz. Based on the idea from Autoconf commit 416b8f50c9bd4e38f9bc48b946505d2a18f6b1fd: Use a shell function to avoid quoting hassles inside a 'trap' argument. * lib/compile (cleanup): New function. (trap): Use it. * lib/depcomp (cleanup): New function. (trap): Use it. * lib/ylwrap (origdirname): New variable. (cleanup): New function. (do_exit): Use it. --- diff --git a/lib/compile b/lib/compile index fc4e9e706..4e4fb7aa9 100755 --- a/lib/compile +++ b/lib/compile @@ -338,7 +338,10 @@ while true; do sleep 1 done # FIXME: race condition here if user kills between mkdir and trap. -trap "rmdir '$lockdir'; exit 1" 1 2 15 +cleanup () { + rmdir "$lockdir" +} +trap "cleanup; exit 1" 1 2 15 # Run the compile. "$@" diff --git a/lib/depcomp b/lib/depcomp index 7226a9a76..3d2205e7e 100755 --- a/lib/depcomp +++ b/lib/depcomp @@ -383,11 +383,11 @@ pgcc) # problems in parallel builds. Use a locking strategy to avoid stomping on # the same $tmpdepfile. lockdir=$base.d-lock - trap " + cleanup () { echo '$0: caught signal, cleaning up...' >&2 - rmdir '$lockdir' - exit 1 - " 1 2 13 15 + rmdir "$lockdir" + } + trap "cleanup; exit 1" 1 2 13 15 numtries=100 i=$numtries while test $i -gt 0; do diff --git a/lib/ylwrap b/lib/ylwrap index 14e63eb7c..bf892d964 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -159,8 +159,12 @@ case $prog in *[\\/]*) prog=`pwd`/$prog ;; esac +origdirname=`pwd` dirname=ylwrap$$ -do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret' +cleanup () { + cd "$origdirname" && rm -rf $dirname > /dev/null 2>&1 +} +do_exit='cleanup; (exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13