aboutsummaryrefslogtreecommitdiffstats
path: root/brp-mangle-shebangs
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2021-03-22 13:13:57 +0100
committerJani Välimaa <wally@mageia.org>2021-09-07 20:05:56 +0300
commitea6fa118f65238c72bee642c7ce60c8b864b6179 (patch)
tree9d1471ef4b969928e60bad46802919687a7a330a /brp-mangle-shebangs
parent6e4702d2c1b6e7b86a549abb671e35db59c4238e (diff)
downloadrpm-setup-ea6fa118f65238c72bee642c7ce60c8b864b6179.tar
rpm-setup-ea6fa118f65238c72bee642c7ce60c8b864b6179.tar.gz
rpm-setup-ea6fa118f65238c72bee642c7ce60c8b864b6179.tar.bz2
rpm-setup-ea6fa118f65238c72bee642c7ce60c8b864b6179.tar.xz
rpm-setup-ea6fa118f65238c72bee642c7ce60c8b864b6179.zip
Fix handling of files without newlines in brp-mangle-shebang
If the file we are trying to mangle a shebang in has 0 lines (as reported by `wc`) `read` command fails to read the first line and the script fails silently. Text files without newlines should not be executable as there is no way for them to contain a shebang. Signed-off-by: Jani Välimaa <wally@mageia.org>
Diffstat (limited to 'brp-mangle-shebangs')
-rwxr-xr-xbrp-mangle-shebangs9
1 files changed, 8 insertions, 1 deletions
diff --git a/brp-mangle-shebangs b/brp-mangle-shebangs
index 4964c09..ef85ee4 100755
--- a/brp-mangle-shebangs
+++ b/brp-mangle-shebangs
@@ -93,7 +93,14 @@ while IFS= read -r line; do
fi
- read shebang_line < "$f" ||:
+ if ! read shebang_line < "$f"; then
+ echo >&2 "*** WARNING: Cannot read the first line from $f, removing executable bit"
+ ts=$(stat -c %y "$f")
+ chmod -x "$f"
+ touch -d "$ts" "$f"
+ continue
+ fi
+
orig_shebang="${shebang_line#\#!}"
if [ "$orig_shebang" = "$shebang_line" ]; then
echo >&2 "*** WARNING: $f is executable but has no shebang, removing executable bit"