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 /tests/find/inode-zero.sh | |
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 'tests/find/inode-zero.sh')
-rwxr-xr-x | tests/find/inode-zero.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/find/inode-zero.sh b/tests/find/inode-zero.sh new file mode 100755 index 00000000..7bfc2698 --- /dev/null +++ b/tests/find/inode-zero.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Ensure find(1) treats inode number 0 correctly. + +# Copyright (C) 2021 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; fu_path_prepend_ +print_ver_ find + +# Skip test unless we find a file with inode number 0. +# GNU/Hurd uses inode 0 for /dev/console. +f='/dev/console' +test -e "${f}" \ + && ino=$( stat -c '%i' "${f}" ) \ + && test "${ino}" = '0' \ + || skip_ "no file with inode number 0 here" + +echo "${f}" > exp || framework_failure_ + +# Ensure -inum works. +# Find by exact inode number 0. +find "${f}" -inum 0 >out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# Find by inode number <1. +find "${f}" -inum -1 >out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +# No match with unrelated inode number. +find "${f}" -inum 12345 >out 2>err || fail=1 +compare /dev/null out || fail=1 +compare /dev/null err || fail=1 + +# Ensure '-printf "%i"' works. +echo 0 > exp || framework_failure_ +find "${f}" -printf '%i\n' >out 2>err || fail=1 +compare exp out || fail=1 +compare /dev/null err || fail=1 + +Exit $fail |