mirror of
git://git.sv.gnu.org/findutils.git
synced 2026-01-31 05:38:59 +01:00
Fix Savannah bug ##20970: Trailing slash on directory arguments breaks -name.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,5 +1,16 @@
|
||||
2007-12-04 James Youngman <jay@gnu.org>
|
||||
|
||||
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.
|
||||
* NEWS: mention this fix.
|
||||
|
||||
Fix Savannah bug #15384, find misbehaves when parent directory is
|
||||
not readable.
|
||||
* find/find.c: Add enumeration member
|
||||
|
||||
4
NEWS
4
NEWS
@@ -7,6 +7,10 @@ GNU findutils NEWS - User visible changes. -*- outline -*- (allout)*
|
||||
|
||||
** Bug Fixes
|
||||
|
||||
#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
|
||||
|
||||
#20751: Avoid memory corruption in find -ls that has been present
|
||||
since 4.2.28.
|
||||
|
||||
|
||||
33
find/pred.c
33
find/pred.c
@@ -967,31 +967,32 @@ pred_ilname (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
|
||||
|
||||
/* 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
|
||||
pred_iname (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
|
||||
{
|
||||
|
||||
@@ -63,6 +63,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/parent.xo \
|
||||
find.posix/perm-vanilla.xo \
|
||||
find.posix/prune.xo \
|
||||
@@ -133,6 +134,7 @@ find.posix/sv-bug-11175.exp \
|
||||
find.posix/sv-bug-12181.exp \
|
||||
find.posix/depth1.exp \
|
||||
find.posix/name.exp \
|
||||
find.posix/nameslash.exp \
|
||||
find.posix/sizes.exp \
|
||||
find.posix/parent.exp \
|
||||
find.posix/perm-vanilla.exp \
|
||||
|
||||
7
find/testsuite/find.posix/nameslash.exp
Normal file
7
find/testsuite/find.posix/nameslash.exp
Normal file
@@ -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
|
||||
1
find/testsuite/find.posix/nameslash.xo
Normal file
1
find/testsuite/find.posix/nameslash.xo
Normal file
@@ -0,0 +1 @@
|
||||
tmp/foo///
|
||||
Reference in New Issue
Block a user