From 40246f9c74720f68f3be7841ac86e0fc527a47e4 Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 4 Dec 2004 13:16:05 +0000 Subject: [PATCH] Fixed savannah bug 11175, wrongly chdir()ing into directories specified on the command line even if they are pruned --- find/find.c | 62 ++++++++++++++++++------------ find/testsuite/Makefile.am | 4 +- find/testsuite/find.posix/sv-bug-11175.exp | 10 +++++ find/testsuite/find.posix/sv-bug-11175.xo | 1 + 4 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 find/testsuite/find.posix/sv-bug-11175.exp create mode 100644 find/testsuite/find.posix/sv-bug-11175.xo diff --git a/find/find.c b/find/find.c index 5ea3ff2..c6e7daa 100644 --- a/find/find.c +++ b/find/find.c @@ -992,10 +992,16 @@ chdir_back (void) } /* Descend PATHNAME, which is a command-line argument. */ - static void process_top_path (char *pathname) { + process_path (pathname, pathname, false, "."); +} + + +static void +old_process_top_path (char *pathname) +{ struct stat stat_buf, cur_stat_buf; boolean dummy; @@ -1007,32 +1013,40 @@ process_top_path (char *pathname) since the kernel can read the stat information out of its inode cache the second time. */ #if USE_SAFE_CHDIR - enum SafeChdirStatus rv = safely_chdir(pathname, TraversingDown, &stat_buf); - - switch (rv) + if ((*xstat) (pathname, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode)) { - case SafeChdirOK: - process_path (pathname, ".", false, "."); - chdir_back (); - return; + enum SafeChdirStatus rv = safely_chdir(pathname, TraversingDown, &stat_buf); - case SafeChdirFailNonexistent: - case SafeChdirFailStat: - case SafeChdirFailWouldBeUnableToReturn: - case SafeChdirFailSymlink: - case SafeChdirFailNotDir: - case SafeChdirFailChdirFailed: - if ((SafeChdirFailNonexistent==rv) && !ignore_readdir_race) - { - error (0, errno, "%s", pathname); - exit_status = 1; - } - else + switch (rv) { - process_path (pathname, pathname, false, "."); + case SafeChdirOK: + process_path (pathname, ".", false, "."); + chdir_back (); + return; + + case SafeChdirFailNonexistent: + case SafeChdirFailStat: + case SafeChdirFailWouldBeUnableToReturn: + case SafeChdirFailSymlink: + case SafeChdirFailNotDir: + case SafeChdirFailChdirFailed: + if ((SafeChdirFailNonexistent==rv) && !ignore_readdir_race) + { + error (0, errno, "%s", pathname); + exit_status = 1; + } + else + { + process_path (pathname, pathname, false, "."); + } + chdir_back (); + return; } - chdir_back (); - return; + } + else + { + /* Not a directory */ + process_path (pathname, pathname, false, "."); } #else if ((*xstat) (pathname, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode)) @@ -1386,7 +1400,7 @@ process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char * char const *dir; boolean deref = following_links() ? true : false; - if (!deref) + if ( (curdepth>0) && !deref) dir = ".."; else { diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index bf50d8b..97ab373 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -13,7 +13,9 @@ EXTRA_DIST = config/unix.exp \ find.gnu/perm.exp \ find.gnu/perm.xo \ find.gnu/prune-default-print.exp \ - find.gnu/prune-default-print.xo + find.gnu/prune-default-print.xo \ + find.posix/sv-bug-11175.exp \ + find.posix/sv-bug-11175.xo CLEANFILES = *.log *.sum site.exp site.bak diff --git a/find/testsuite/find.posix/sv-bug-11175.exp b/find/testsuite/find.posix/sv-bug-11175.exp new file mode 100644 index 0000000..06dd160 --- /dev/null +++ b/find/testsuite/find.posix/sv-bug-11175.exp @@ -0,0 +1,10 @@ +# tests for Savannah bug 11175 (should not check perms of pruned dir) +exec rm -rf tmp +exec mkdir tmp +exec mkdir tmp/noxdir +exec chmod 700 tmp +exec chmod 600 tmp/noxdir +#find_start p {tmp/noxdir -prune -type d -print} +find_start p {tmp -name noxdir -prune -type d -print} +exec chmod 700 tmp/noxdir +exec rm -rf tmp diff --git a/find/testsuite/find.posix/sv-bug-11175.xo b/find/testsuite/find.posix/sv-bug-11175.xo new file mode 100644 index 0000000..cd9c95f --- /dev/null +++ b/find/testsuite/find.posix/sv-bug-11175.xo @@ -0,0 +1 @@ +tmp/noxdir -- 2.11.4.GIT