]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
install: support stripping files with a leading hyphen
authorPádraig Brady <P@draigBrady.com>
Fri, 21 Apr 2023 18:07:02 +0000 (19:07 +0100)
committerPádraig Brady <P@draigBrady.com>
Fri, 21 Apr 2023 18:13:52 +0000 (19:13 +0100)
* src/install.c (strip): Prepend "./" to file names with a leading "-".
* tests/install/strip-program.sh: Add a test case.
* NEWS: Mention the bug fix.
Reported in https://bugs.debian.org/1034429

NEWS
src/install.c
tests/install/strip-program.sh

diff --git a/NEWS b/NEWS
index 21129c8fc4d5383b624005e00d7a20f2e6083423..8edfa8080e28907eee92c69ef3404bb4d0edb79d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Bug fixes
+
+  install --strip now supports installing to files with a leading hyphen.
+  Previously such file names would have caused the strip process to fail.
+  [This bug was present in "the beginning".]
+
 
 * Noteworthy changes in release 9.3 (2023-04-18) [stable]
 
index 3aa6ea92b6ef29e5ab995212107cded2b1b6ed91..272dfcb8fe1400776e4526a53b5235c21c078368 100644 (file)
@@ -502,8 +502,13 @@ strip (char const *name)
       error (0, errno, _("fork system call failed"));
       break;
     case 0:                    /* Child. */
-      execlp (strip_program, strip_program, name, NULL);
-      die (EXIT_FAILURE, errno, _("cannot run %s"), quoteaf (strip_program));
+      {
+        char const *safe_name = name;
+        if (name && *name == '-')
+          safe_name = file_name_concat (".", name, NULL);
+        execlp (strip_program, strip_program, safe_name, NULL);
+        die (EXIT_FAILURE, errno, _("cannot run %s"), quoteaf (strip_program));
+      }
     default:                   /* Parent. */
       if (waitpid (pid, &status, 0) < 0)
         error (0, errno, _("waiting for strip"));
index 0a702f7fae79bd8211006b9f95e0cbcf217f8690..1b7de52a24b01e42841ee79b4ba54036df444a7c 100755 (executable)
@@ -27,7 +27,6 @@ sed s/b/B/ \$1 > \$1.t && mv \$1.t \$1
 EOF
 chmod a+x b || framework_failure_
 
-
 echo abc > src || framework_failure_
 echo aBc > exp || framework_failure_
 ginstall src dest -s --strip-program=./b || fail=1
@@ -37,4 +36,13 @@ compare exp dest || fail=1
 returns_ 1 ginstall src dest2 -s --strip-program=./FOO || fail=1
 test -e dest2 && fail=1
 
+# Ensure naked hyphens not passed
+cat <<EOF > no-hyphen || framework_failure_
+#!$SHELL
+printf -- '%s\\n' "\$1" | grep '^[^-]'
+EOF
+chmod a+x no-hyphen || framework_failure_
+
+ginstall -s --strip-program=./no-hyphen -- src -dest || fail=1
+
 Exit $fail