Change the executing of a 0-byte file to be an error...

Ceri Davies ceri at
Fri Jun 10 11:11:05 GMT 2005

On Fri, Jun 10, 2005 at 01:33:02AM -0400, Garance A Drosihn wrote:
> A few months ago, I had a system panic happen right in the middle of
> a 'installworld'.  Right now I don't care about the panic itself
> (IIRC, it was a hardware problem), but there was one unexpected
> side-effect which caused me more trouble than the original panic.
> And all that trouble boils down to the following:
>    If a file is empty and executable, that empty file can be
>    executed without generating any error.
> The panic caused a few files in /usr/bin to end up as zero-byte
> executable files, but I didn't realize that.  I ended up doing
> another buildworld, I think it was, and ended up digging myself
> into a deeper and deeper hole.  The problem included things like
> makefile rules calling:
>      somecmd | sort -blah | domore
> where the 'sort' command had turned into one of those zero-byte
> executable files.  The basic result was that the more I tried to
> rebuild parts of the world, the more screwed up the system became.
> By the time I was done, I had to do a clean install from CD-ROM
> to get it back to working order.
> Can anyone think of a real-world problem that would come up if the
> system was changed so that executing a 0-byte file would cause an
> error?  I read through a few likely pages in SUSv3, and it looked
> like the behavior for executing an 0-byte file is not explicitly
> defined.  Of course, it might be that I was simply looking in the
> wrong part of the standard.
> It does seem like empty files are also executed without error on a
> few other OS's I tried, but I don't understand why that behavior
> would be desirable.

Are you sure?  It seems to be a function of the shell more than
anything; the transcript below does exactly the same on both FreeBSD
4-STABLE and Solaris 8:

$ sh
$ PS1='sh$ '
sh$ touch empty ; chmod +x empty
sh$ ./empty
sh$ echo $?
sh$ PS1='zsh$ ' zsh
zsh$ zsh
zsh$ ./empty
zsh: exec format error: ./empty

Only two things are infinite, the universe and human stupidity, and I'm
not sure about the former.			  -- Einstein (attrib.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url :

More information about the freebsd-standards mailing list