aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/find/function.c
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2014-01-05 23:01:28 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2014-01-05 23:01:28 +0000
commite810bef7417cf0b8fb400cb02d2821dc0b8a2cd2 (patch)
treeb4df40028a96c27e13ec1f1ab4e104b18b8803d0 /usr.bin/find/function.c
parent02c7dba91926f0279f1e5b170bb481472418c2d0 (diff)
Notes
Diffstat (limited to 'usr.bin/find/function.c')
-rw-r--r--usr.bin/find/function.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index b65709948bba..9f156756cc56 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -1125,7 +1125,17 @@ f_name(PLAN *plan, FTSENT *entry)
ssize_t len;
if (plan->flags & F_LINK) {
- len = readlink(entry->fts_path, fn, sizeof(fn) - 1);
+ /*
+ * The below test both avoids obviously useless readlink()
+ * calls and ensures that symlinks with existent target do
+ * not match if symlinks are being followed.
+ * Assumption: fts will stat all symlinks that are to be
+ * followed and will return the stat information.
+ */
+ if (entry->fts_info != FTS_NSOK && entry->fts_info != FTS_SL &&
+ entry->fts_info != FTS_SLNONE)
+ return 0;
+ len = readlink(entry->fts_accpath, fn, sizeof(fn) - 1);
if (len == -1)
return 0;
fn[len] = '\0';