From ea6fa118f65238c72bee642c7ce60c8b864b6179 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Mon, 22 Mar 2021 13:13:57 +0100 Subject: Fix handling of files without newlines in brp-mangle-shebang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- brp-mangle-shebangs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'brp-mangle-shebangs') 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" -- cgit v1.2.1