[dev] [sbase] Bugs in find

From: Tavian Barnes <tavianator_AT_tavianator.com>
Date: Wed, 26 Sep 2018 20:48:07 -0400

Hi! As the author of a find-compatible tool, whenever I find another
find implementation I run my testsuite against it to see if I find any
bugs in either one. sbase/find helped me identify many places in my
POSIX tests that use extensions to POSIX when they shouldn't, so
thanks! Here's the bugs that I found in sbase/find:

- Errors reported for broken symlinks in -L/-H modes -

$ mkdir foo
$ ln -s nowhere foo/broken
$ touch foo/bar
$ ln -s bar/baz foo/notdir
$ ./find -L foo
./find: failed to stat foo/broken: No such file or directory
./find: failed to stat foo/notdir: Not a directory
$ ./find -H foo/broken
./find: failed to stat foo/broken: No such file or directory
$ ./find -H foo/notdir
./find: failed to stat foo/notdir: Not a directory

For -H/-L, POSIX says

> If the referenced file does not exist, the file information and type shall be for the link itself.

- Names longer than PATH_MAX are broken -

POSIX says

> The find utility shall be able to descend to arbitrary depths in a file hierarchy and shall not fail due to path length limitations (unless a path operand specified by the application exceeds {PATH_MAX} requirements).


$ name="0123456789ABCDEF"
$ name="${name}${name}${name}${name}"
$ name="${name}${name}${name}${name}"
$ name="${name:0:255}"
$ (mkdir deep && cd deep && for i in {1..17}; do mkdir $name && cd $name; done)
$ ./find deep
./find: failed to stat deep/...ABCDE: File name too long

Despite that, it exits successfully, which is probably also a bug.

- find -newer follows symbolic links -

$ mkdir foo
$ touch foo/bar
$ ln -s bar foo/baz
$ touch foo/qux
$ ./find foo -newer foo/baz

foo/baz is not newer than itself though.

- find -perm doesn't support X -

$ ./find . -perm a+rX,u+w
./find: a+rX,u+w: invalid mode

About the mode format for -perm, POSIX says

> It shall be identical in format to the symbolic_mode operand described in chmod

chmod supports X, so find should too.

If you want to run these tests yourself, clone
https://github.com/tavianator/bfs and run

$ ./tests.sh --bfs=path/to/sbase/find --posix

Tavian Barnes
Received on Thu Sep 27 2018 - 02:48:07 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 27 2018 - 03:00:08 CEST