find: Fix -lname and -ilname.

The code did not take into account that readlink() does not add a
terminating '\0', and therefore did not work reliably.

As before, symlinks of length PATH_MAX or more are not handled correctly.
(These can only be created on other operating systems.)

PR:		bin/185393
Submitted by:	Ben Reser (original version)
MFC after:	1 week
This commit is contained in:
jilles 2014-01-05 21:44:04 +00:00
parent 775cb4ad60
commit 6f9ebfa0c3

View File

@ -1122,11 +1122,14 @@ 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)
len = readlink(entry->fts_path, 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,