]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
compile, depcomp, ylwrap: Fix quoting bug in 'trap' command.
authorBruno Haible <bruno@clisp.org>
Fri, 29 May 2026 13:55:27 +0000 (15:55 +0200)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 29 May 2026 21:59:29 +0000 (14:59 -0700)
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.

lib/compile
lib/depcomp
lib/ylwrap

index fc4e9e706f3b5dc72f5a15331b57e753da20027b..4e4fb7aa99ab961150a5fd4bf177ed61f8f4f989 100755 (executable)
@@ -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.
 "$@"
index 7226a9a7623d3a2a840a8b0d36d15f4227363813..3d2205e7e79dae2bcf87d509b3e0c666ef4a8dfb 100755 (executable)
@@ -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
index 14e63eb7cd040dc7acf6a28dff80f2c28ce20ec8..bf892d964bf7472ea9ab6ed35aa78edcfb7e9298 100755 (executable)
@@ -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