ls -d broken (should not follow symlink)

Isaac Dunham ibid.ag at gmail.com
Thu Oct 30 04:54:58 UTC 2014


Hello,
I've run across a bug that occurs in both busybox and toybox versions of ls.
OS is Alpine Linux edge, which uses current musl and busybox 1.22.1.
git log indicates no relevant changes to busybox ls.
I'm using current toybox.

According to POSIX, "ls -d" means:
-d     Do not follow symbolic links named as operands unless the -H  or
       -L  options  are specified. Do not treat directories differently
       than other types of files.  The  use  of  -d  with  -R  produces
       unspecified results.

Simple testcase would be:
ln -s /dev/null/nothing nothing	#make broken symlink
ls -d nothing			#Which should say without error:

nothing

I was checking for missing symlinks to toybox in a small project; I have
toybox at bin/toybox, but not at /bin/toybox.
All symlinks point to /bin/toybox, however.

I tried to use this simple test to see if there were any links I 
needed to make:

$ for f in `bin/toybox`; do ls -d *bin/$f || echo MISSING $f; done

ls is currently busybox ls.

However, ls attempted to follow every link, showing all as missing.
Repeating this with toybox got similar results.

(Yes, I'm aware that I can use test -L/test -h instead. And it works.
But ls -d should not follow symlinks.)

Thanks,
Isaac Dunham



More information about the busybox mailing list