From fe0ea843f2c1ca0d1bdd2a0c9ac02f7c1fd62c6a Mon Sep 17 00:00:00 2001 From: jay Date: Tue, 4 Dec 2007 01:26:55 +0000 Subject: [PATCH] Fix Savannah bug #15384, find misbehaves when parent directory is not readable. --- ChangeLog | 9 +++++++++ NEWS | 5 +++++ find/find.c | 26 ++++++++++++++++++++++---- find/testsuite/Makefile.am | 2 ++ find/testsuite/find.posix/parent.exp | 7 +++++++ find/testsuite/find.posix/parent.xo | 1 + 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 find/testsuite/find.posix/parent.exp create mode 100644 find/testsuite/find.posix/parent.xo diff --git a/ChangeLog b/ChangeLog index a5ec94e..bd8a37d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2007-12-04 James Youngman + Fix Savannah bug #15384, find misbehaves when parent directory is + not readable. + * find/testsuite/find.posix/parent.exp: New test + * find/testsuite/find.posix/parent.xo: New test + * find/testsuite/Makefile.am (EXTRA_DIST_EXP, EXTRA_DIST_XO): + Added parent.exp, parent.xo. + * find/find.c (safely_chdir): If safely_chdir_nofollow fails with + SafeChdirFailDestUnreadable, fall back on safely_chdir_lstat. + * find/find.1: Formatting fixes; options should be in bold. 2007-12-02 James Youngman diff --git a/NEWS b/NEWS index 4191bbd..9225889 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ GNU findutils NEWS - User visible changes. -*- outline -*- (allout) * Major changes in release 4.3.12-CVS +** Bug Fixes + +#15384: Find misbehaves when parent directory is not readable. + + * Major changes in release 4.3.11, 2007-12-02 ** Functional changes diff --git a/find/find.c b/find/find.c index bc6f8e9..1688cf7 100644 --- a/find/find.c +++ b/find/find.c @@ -879,10 +879,28 @@ safely_chdir(const char *dest, options.open_nofollow_available = false; #endif if (options.open_nofollow_available) - result = safely_chdir_nofollow(dest, direction, statbuf_dest, symlink_follow_option, did_stat); - else - result = safely_chdir_lstat(dest, direction, statbuf_dest, symlink_follow_option, did_stat); - return result; + { + result = safely_chdir_nofollow(dest, direction, statbuf_dest, + symlink_follow_option, did_stat); + if (SafeChdirFailDestUnreadable != result) + { + return result; + } + else + { + /* Savannah bug #15384: fall through to use safely_chdir_lstat + * if the directory is not readable. + */ + /* Do nothing. */ + } + + } + /* Even if O_NOFOLLOW is available, we may need to use the alternative + * method, since parent of the start point may be executable but not + * readable. + */ + return safely_chdir_lstat(dest, direction, statbuf_dest, + symlink_follow_option, did_stat); } diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index e73e520..3712f0c 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -81,6 +81,7 @@ find.posix/depth1.xo \ find.posix/sizes.xo \ find.posix/name.xo \ find.posix/nameslash.xo \ +find.posix/parent.xo \ find.posix/perm-X.xo \ find.posix/perm-vanilla.xo \ find.posix/posixnot.xo \ @@ -138,6 +139,7 @@ find.gnu/mindepth-badarg.exp \ find.gnu/name-opt.exp \ find.gnu/name-period.exp \ find.gnu/name-slash.exp \ +find.posix/parent.exp \ find.gnu/path.exp \ find.gnu/print_stdout.exp \ find.gnu/print0.exp \ diff --git a/find/testsuite/find.posix/parent.exp b/find/testsuite/find.posix/parent.exp new file mode 100644 index 0000000..1cdca3b --- /dev/null +++ b/find/testsuite/find.posix/parent.exp @@ -0,0 +1,7 @@ +# test for handling of unreadable parent directory +exec rm -rf tmp +exec mkdir tmp tmp/dir +exec chmod a-rw tmp +find_start p {tmp/dir} +exec chmod u+rw tmp +exec rm -rf tmp diff --git a/find/testsuite/find.posix/parent.xo b/find/testsuite/find.posix/parent.xo new file mode 100644 index 0000000..2dc4706 --- /dev/null +++ b/find/testsuite/find.posix/parent.xo @@ -0,0 +1 @@ +tmp/dir -- 2.11.4.GIT