diff options
author | Bernhard Voelker <mail@bernhard-voelker.de> | 2021-12-26 11:09:22 +0100 |
---|---|---|
committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2021-12-29 20:36:19 +0100 |
commit | 9290525c774290e451b13f7cdf81262d7656e3ed (patch) | |
tree | a13411c530a5aeeb6b6bcf1b20cf4bd93016f9fa /find/util.c | |
parent | 68979e578cbea71211af45685561df52232623d1 (diff) | |
download | findutils-9290525c774290e451b13f7cdf81262d7656e3ed.tar.gz |
find: fix visiting of files with inode number Zero
On GNU/Hurd, the value 0 is a valid inode number, and is e.g. used
for /dev/console and /dev/tty. The find(1) program aborted on this
platform when the user specified the -inum test and when the search
visited such a file.
$ find /dev/null /dev/tty -inum 40799 -printf '%i:%p\n'
40799:/dev/null
find: util.c:330: get_info: Assertion `p->st_ino' failed.
Aborted
Likewise, 'find -printf %i' aborted when hitting such a file.
* find/defs.h (get_info): Remove declaration.
* find/pred.c (pred_inum): Remove the redundant assert for ST_INO
as parse_inum sets need_inum=true which ensures that the inode number
is known.
* find/util.c (get_info): Declare static, and simplify: remove the
assertions for the inode number and file type.
While at it, add condition !state.have_stat in the need_stat case
for consistency.
* tests/find/inode-zero.sh: Add test.
* tests/local.mk (all_tests): Reference it.
Problem introduced by the inum optimisation in commit 2bf001636e6.
Reported by Andrea Monaco <andrea.monaco@autistici.org> in
https://lists.gnu.org/r/bug-findutils/2021-12/msg00008.html
Diffstat (limited to 'find/util.c')
-rw-r--r-- | find/util.c | 31 |
1 files changed, 5 insertions, 26 deletions
diff --git a/find/util.c b/find/util.c index afd9880e..59f80659 100644 --- a/find/util.c +++ b/find/util.c @@ -280,7 +280,7 @@ get_statinfo (const char *pathname, const char *name, struct stat *p) /* Get the stat/type/inode information for a file, if it is not * already known. Returns 0 on success (or if we did nothing). */ -int +static int get_info (const char *pathname, struct stat *p, struct predicate *pred_ptr) @@ -290,7 +290,7 @@ get_info (const char *pathname, /* If we need the full stat info, or we need the type info but don't * already have it, stat the file now. */ - if (pred_ptr->need_stat) + if (pred_ptr->need_stat && !state.have_stat) { todo = true; /* need full stat info */ } @@ -316,31 +316,10 @@ get_info (const char *pathname, } if (todo) { - int result = get_statinfo (pathname, state.rel_pathname, p); - if (result != 0) - { - return -1; /* failure. */ - } - else - { - /* Verify some postconditions. We can't check st_mode for - non-zero-ness because of Savannah bug #16378 (which is - that broken NFS servers can return st_mode==0). */ - if (pred_ptr->need_type) - { - assert (state.have_type); - } - if (pred_ptr->need_inum) - { - assert (p->st_ino); - } - return 0; /* success. */ - } - } - else - { - return 0; /* success; nothing to do. */ + if (get_statinfo (pathname, state.rel_pathname, p) != 0) + return -1; /* failure. */ } + return 0; /* success, or nothing to do. */ } /* Determine if we can use O_NOFOLLOW. |