misc/158206: /bin/sh doesn't properly return IO errors to
conditionals in a script
culrich at csnstores.com
Thu Jun 23 16:10:14 UTC 2011
>Synopsis: /bin/sh doesn't properly return IO errors to conditionals in a script
>Arrival-Date: Thu Jun 23 16:10:14 UTC 2011
>Originator: Chris Ulrich
>Release: amd64 freebsd 8.2-RELEASE
FreeBSD svn.csnzoo.com 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Feb 17 02:41:51 UTC 2011 root at mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
a /bin/sh script writing to a closed file descriptor doesn't pass the IO error it receives from the write to the script itself.
write these two scripts:
while echo -n . ; do : ; done
while printf . ; do : ; done
now run each script with std-out closed, ie (assuming your interactive shell is bourne shell or similar):
$ sh ./bomb-echo.sh >&-
$ sh ./bomb-printf.sh >&-
both should exit instantly because echo *should* get an error from writing to a closed file descriptor. Instead both spin madly until they get a kill signal or you truss them (the last bit of stuff you see when you truss them is:
72238: sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0)
72238: write(1,".",1) ERR#9 'Bad file descriptor'
72238: process exit, rval = 0
which itself is another
sorry. don't know C.
More information about the freebsd-bugs