From d8e46e3a7d9c5e92d6b39d407b594299ac1994a0 Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 26 Nov 2007 10:37:40 +0000 Subject: [PATCH] Fixed Savannah bug #20970: Trailing slash on directory arguments breaks -name --- ChangeLog | 10 ++++++++++ NEWS | 5 ++++- find/pred.c | 31 +++++++++++++++---------------- find/testsuite/Makefile.am | 2 ++ find/testsuite/find.posix/nameslash.exp | 7 +++++++ find/testsuite/find.posix/nameslash.xo | 1 + 6 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 find/testsuite/find.posix/nameslash.exp create mode 100644 find/testsuite/find.posix/nameslash.xo diff --git a/ChangeLog b/ChangeLog index a350005..674246d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2007-11-26 James Youngman + Fix Savannah bug #20970, handling of trailing slashes with -name. + * find/pred.c (pred_name_common): Strip trailing slashes from the + pathname before applying fnmatch() to it. This fixes Savannah bug + #20970. + * find/testsuite/find.posix/nameslash.exp: Test case for bug #20970. + * find/testsuite/find.posix/nameslash.xo: Expected output file for + same. + * find/testsuite/Makefile.am (EXTRA_DIST_EXP): Added nameslash.exp. + (EXTRA_DIST_XO): Added nameslash.xo. + Fix Savannah bug #21634, No copy of FDL1.2 included in source code. * doc/find.texi: Change license to the GNU Free Documentation diff --git a/NEWS b/NEWS index b41d9e9..b88c754 100644 --- a/NEWS +++ b/NEWS @@ -8,12 +8,15 @@ When the POSIXLY_CORRECT environment variable is set, "find -perm starting with '+' which are not valid in POSIX are also rejected. ** Bug Fixes - #21039: Setting the POSIXLY_CORRECT environment variable now turns off warnings by default, because POSIX requires that only diagnostic messages (and -ok prompts) are printed on STDERR, and diagnostic messages must also result in a nonzero exit status. +#20970: Trailing slash on directory arguments breaks -name. "find +foo/ -name foo" now correctly matches foo and printf foo/. See POSIX +interp http://www.opengroup.org/austin/interps/uploads/40/14959/AI-186.txt + ** Documentation Fixes #21270: Formatting fixes to the xargs.1 manual page, including making diff --git a/find/pred.c b/find/pred.c index 730a876..2eb0f32 100644 --- a/find/pred.c +++ b/find/pred.c @@ -1156,29 +1156,28 @@ pred_ilname (const char *pathname, struct stat *stat_buf, struct predicate *pred /* Common code between -name, -iname. PATHNAME is being visited, STR is name to compare basename against, and FLAGS are passed to - fnmatch. */ + fnmatch. Recall that 'find / -name /' is one of the few times where a '/' + in the -name must actually find something. */ static boolean pred_name_common (const char *pathname, const char *str, int flags) { - /* Prefer last_component over base_name, to avoid malloc when - possible. */ - char *base = last_component (pathname); + char *p; + boolean b; + /* We used to use last_component() here, but that would not allow us to modify the + * input string, which is const. We could optimise by duplicating the string only + * if we need to modify it, and I'll do that if there is a measurable + * performance difference on a machine built after 1990... + */ + char *base = base_name (pathname); + /* remove trailing slashes, but leave "/" or "//foo" unchanged. */ + strip_trailing_slashes(base); - /* base is empty only if pathname is a file system root. But recall - that 'find / -name /' is one of the few times where a '/' in the - -name must actually find something. */ - if (!*base) - { - boolean b; - base = base_name (pathname); - b = fnmatch (str, base, flags) == 0; - free (base); - return b; - } /* FNM_PERIOD is not used here because POSIX requires that it not be. * See http://standards.ieee.org/reading/ieee/interp/1003-2-92_int/pasc-1003.2-126.html */ - return fnmatch (str, base, flags) == 0; + b = fnmatch (str, base, flags) == 0; + free (base); + return b; } boolean diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index 089820e..4017d56 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -80,6 +80,7 @@ find.posix/sv-bug-12181.xo \ find.posix/depth1.xo \ find.posix/sizes.xo \ find.posix/name.xo \ +find.posix/nameslash.xo \ find.posix/perm-X.xo \ find.posix/perm-vanilla.xo \ find.posix/posixnot.xo \ @@ -191,6 +192,7 @@ find.posix/sv-bug-12181.exp \ find.posix/depth1.exp \ find.posix/sizes.exp \ find.posix/name.exp \ +find.posix/nameslash.exp \ find.posix/name-missing.exp \ find.posix/perm-X.exp \ find.posix/perm-vanilla.exp \ diff --git a/find/testsuite/find.posix/nameslash.exp b/find/testsuite/find.posix/nameslash.exp new file mode 100644 index 0000000..1aaf220 --- /dev/null +++ b/find/testsuite/find.posix/nameslash.exp @@ -0,0 +1,7 @@ +# tests for -name and trailing slashes. +# See http://www.opengroup.org/austin/interps/uploads/40/14959/AI-186.txt +# This is a test for Savannah bug #20970. +exec rm -rf tmp +exec mkdir tmp tmp/foo tmp/bar +find_start p {tmp/foo/// tmp/bar/// -name foo -o -name 'bar?*'} +exec rm -rf tmp diff --git a/find/testsuite/find.posix/nameslash.xo b/find/testsuite/find.posix/nameslash.xo new file mode 100644 index 0000000..e94ef73 --- /dev/null +++ b/find/testsuite/find.posix/nameslash.xo @@ -0,0 +1 @@ +tmp/foo/// -- 2.11.4.GIT