Date: Tue, 14 Jan 2014 21:35:25 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r260651 - stable/9/usr.bin/find Message-ID: <201401142135.s0ELZPVT076326@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Tue Jan 14 21:35:25 2014 New Revision: 260651 URL: http://svnweb.freebsd.org/changeset/base/260651 Log: MFC r260336,r260355: find: Fix -lname and -ilname: * Take into account that readlink() does not add a terminating '\0'. * Do not match symlinks that are followed because of -H or -L. This is explicitly documented in GNU find's info file and is like -type l. * Fix matching symlinks in subdirectories when fts changes directories. As before, symlinks of length PATH_MAX or more are not handled correctly. (These can only be created on other operating systems.) Also, avoid some readlink() calls on files that are obviously not symlinks (because of fts(3) restrictions, not all of them). PR: bin/185393 Submitted by: Ben Reser (parts, original version) Modified: stable/9/usr.bin/find/find.1 stable/9/usr.bin/find/function.c Directory Properties: stable/9/usr.bin/find/ (props changed) Modified: stable/9/usr.bin/find/find.1 ============================================================================== --- stable/9/usr.bin/find/find.1 Tue Jan 14 21:20:51 2014 (r260650) +++ stable/9/usr.bin/find/find.1 Tue Jan 14 21:35:25 2014 (r260651) @@ -31,7 +31,7 @@ .\" @(#)find.1 8.7 (Berkeley) 5/9/95 .\" $FreeBSD$ .\" -.Dd September 9, 2012 +.Dd January 5, 2014 .Dt FIND 1 .Os .Sh NAME @@ -502,6 +502,8 @@ Like .Ic -name , but the contents of the symbolic link are matched instead of the file name. +Note that this only matches broken symbolic links +if symbolic links are being followed. This is a GNU find extension. .It Ic -ls This primary always evaluates to true. Modified: stable/9/usr.bin/find/function.c ============================================================================== --- stable/9/usr.bin/find/function.c Tue Jan 14 21:20:51 2014 (r260650) +++ stable/9/usr.bin/find/function.c Tue Jan 14 21:35:25 2014 (r260651) @@ -1082,11 +1082,24 @@ f_name(PLAN *plan, FTSENT *entry) { char fn[PATH_MAX]; const char *name; + ssize_t len; if (plan->flags & F_LINK) { - name = fn; - if (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'; + name = fn; } else name = entry->fts_name; return !fnmatch(plan->c_data, name,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401142135.s0ELZPVT076326>