From 27a8c7a7c29c8ee850279d607d35793cbb91c983 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Mon, 22 Mar 2021 13:13:57 +0100 Subject: [PATCH] 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. --- brp-mangle-shebangs | 9 ++++++++- redhat-rpm-config.spec | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/brp-mangle-shebangs b/brp-mangle-shebangs index 98990c0..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" diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index b86a94d..bc0910d 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -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 - 182-1 +- Fix handling of files without newlines in brp-mangle-shebang + * Wed Mar 10 2021 Kalev Lember - 181-1 - BRP Python Bytecompile: Avoid hardcoding /usr/bin prefix for python