From acebb585f710fccf9029ecb753ee462c2c79dc0d Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sun, 24 Feb 2008 00:01:06 +0000 Subject: [PATCH] The matching in -lname and -ilname are on the contents of the link itself, not on the type of the file. As such, do a readlink to get the symbolic link's contents and fail to match if the path isn't a symbolic link. Pointed out by: des@ --- usr.bin/find/function.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 4f823a25b513..c3c90f84a18f 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1087,9 +1087,16 @@ c_ls(OPTION *option, char ***argvp __unused) int f_name(PLAN *plan, FTSENT *entry) { - if ((plan->flags & F_LINK) && !S_ISLNK(entry->fts_statp->st_mode)) - return 0; - return !fnmatch(plan->c_data, entry->fts_name, + char fn[PATH_MAX]; + const char *name; + + if (plan->flags & F_LINK) { + name = fn; + if (readlink(entry->fts_path, fn, sizeof(fn)) == -1) + return 0; + } else + name = entry->fts_name; + return !fnmatch(plan->c_data, name, plan->flags & F_IGNCASE ? FNM_CASEFOLD : 0); } @@ -1102,8 +1109,6 @@ c_name(OPTION *option, char ***argvp) pattern = nextarg(option, argvp); new = palloc(option); new->c_data = pattern; - if (new->flags & F_LINK) - ftsoptions &= ~FTS_NOSTAT; return new; }