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.
This commit is contained in:
Lumir Balhar 2021-03-22 13:13:57 +01:00
parent 61b19ee1b2
commit 27a8c7a7c2
2 changed files with 12 additions and 2 deletions

View File

@ -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"

View File

@ -6,7 +6,7 @@
Summary: Red Hat specific rpm configuration files
Name: redhat-rpm-config
Version: 181
Version: 182
Release: 1%{?dist}
# No version specified.
License: GPL+
@ -213,6 +213,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua
%{_rpmconfigdir}/macros.d/macros.kmp
%changelog
* Mon Mar 22 2021 Lumír Balhar <lbalhar@redhat.com> - 182-1
- Fix handling of files without newlines in brp-mangle-shebang
* Wed Mar 10 2021 Kalev Lember <klember@redhat.com> - 181-1
- BRP Python Bytecompile: Avoid hardcoding /usr/bin prefix for python