From: Pádraig Brady
Date: Fri, 21 Apr 2023 18:07:02 +0000 (+0100)
Subject: install: support stripping files with a leading hyphen
X-Git-Tag: v9.4~160
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bab375973e62e9fcc0b41451d637134073e3007;p=thirdparty%2Fcoreutils.git
install: support stripping files with a leading hyphen
* 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
---
diff --git a/NEWS b/NEWS
index 21129c8fc4..8edfa8080e 100644
--- 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]
diff --git a/src/install.c b/src/install.c
index 3aa6ea92b6..272dfcb8fe 100644
--- a/src/install.c
+++ b/src/install.c
@@ -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"));
diff --git a/tests/install/strip-program.sh b/tests/install/strip-program.sh
index 0a702f7fae..1b7de52a24 100755
--- a/tests/install/strip-program.sh
+++ b/tests/install/strip-program.sh
@@ -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 <