Here is a patch that makes bash treat being unable to read the input
file as a fatal error.  It's still not ideal:
 * Fatal errors should give an exit status of 127, not 2
 * Failure to read the script file should probably invoke a trap
   (which one??)
 * The filename isn't printed in the error message, although sometimes
   it will be included because it's the script (note that this
   condition can occur if the file isn't stdin if for example the
   file can be partially read, or if it cannot be seeked - the
   current failure for `bash .' is caused only because it noticed the
   problem while trying to decide whether `.' is a binary file which
   shouldn't be executed.

Nevertheless, this patch should be applied because it turns a silent
failure exiting 0 into a noisy one exiting non-0, which is at least an
improvement.

FYI, I have uploaded this patch into ubuntu as bash 3.1-2ubuntu9.

Ian.

diff -u bash-3.1/debian/rules bash-3.1/debian/rules
--- bash-3.1/debian/rules
+++ bash-3.1/debian/rules
@@ -520,6 +520,7 @@
        po-sv \
        bash-subst-param-length \
        pgrp-pipe \
+       input-err \
        read-memleak \
        login-shell \
 
diff -u bash-3.1/debian/changelog bash-3.1/debian/changelog
--- bash-3.1/debian/changelog
+++ bash-3.1/debian/changelog
@@ -1,3 +1,13 @@
+bash (3.1-2ubuntu9) dapper; urgency=low
+
+  * Make bash die if it cannot read its input file.  Debian #320036.
+    (This is not an ideal fix because, for example, the exit status is
+    still wrong - it should be 127, not 2.  Also, the filename is not
+    printed.  Unfortunately the code is badly tangled making this small
+    fix the most appropriate approach.)
+
+ -- Ian Jackson <[EMAIL PROTECTED]>  Wed,  5 Apr 2006 15:31:55 +0100
+
 bash (3.1-2ubuntu8) dapper; urgency=low
 
   * clear_console: Only get rid of any history in the scrollback, if
only in patch2:
unchanged:
--- bash-3.1.orig/debian/patches/input-err.dpatch
+++ bash-3.1/debian/patches/input-err.dpatch
@@ -0,0 +1,30 @@
+#! /bin/sh -e
+
+if [ $# -eq 3 -a "$2" = '-d' ]; then
+    pdir="-d $3"
+elif [ $# -ne 1 ]; then
+    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+    exit 1
+fi
+case "$1" in
+    -patch) patch $pdir -f --no-backup-if-mismatch -p0 < $0;;
+    -unpatch) patch $pdir -f --no-backup-if-mismatch -R -p0 < $0;;
+    *)
+       echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
+       exit 1
+esac
+exit 0
+
+# DP: Define PGRP_PIPE to avoid race condition.
+
+--- input.c~   2005-07-14 13:29:08.000000000 +0100
++++ input.c    2006-04-05 14:51:50.000000000 +0100
+@@ -454,7 +454,7 @@
+       if (nr == 0)
+       bp->b_flag |= B_EOF;
+       else
+-      bp->b_flag |= B_ERROR;
++      fatal_error("error reading input file: %s", strerror(errno));
+       return (EOF);
+     }
+ 

Reply via email to