cp /dev/null

Rob Landley rob at landley.net
Tue Nov 1 21:56:47 UTC 2005


On Tuesday 01 November 2005 13:03, John Kelly wrote:
> cp /dev/null myfile
>
> should create a (normal) empty file named "myfile" but it copies the
> device file /dev/null, as though the -a flag was specified.
>
> This bug has been around for a while, because it fails in 1.00 and
> snapshot 20051030.  Same problem for /dev/zero, maybe others too.
>
> I discovered this when trying to run e2fsprogs make check (mainline,
> not the busybox version).  Most of the tests started failing, because
> the test script does a cp /dev/null to create an empty file.
>
> This is such a common shell technique, funny that nobody else noticed
> the bug before now.
>
> Guess I should file a bug report ...

This counts.

Hmmm...  FILEUTILS_DEREFERENCE (horrible name) selects the use of lstat 
instead of stat, but this is still giving us a device instead of a file.  And 
that's horked...

Ok, this is an area in which we are definitely trying to be too darn clever 
for our own good...

Ow.  This code hurts.  Trying to resist the urge to do a largeish cleaup.  
(cp_mv_stat can return -1, 0, 1, or 3.  No 2.  Why?  Doesn't say...)

Evil, evil, evil...

But the problem was in libbb/copy_file.c, which I had to untangle a bit before 
fixing.  Just checked in a fixed that worked for me, but who knows what else 
I broke touch code that gnarly.  Try it now (current svn -devel branch) and 
let me know if it's working for you...

Rob



More information about the busybox mailing list