summaryrefslogtreecommitdiffstats
path: root/usr.bin/find
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-01-05 21:44:04 +0000
committerjilles <jilles@FreeBSD.org>2014-01-05 21:44:04 +0000
commit6f9ebfa0c3159b8dd19fa1a837691a7deaaa3842 (patch)
tree43de49e4d358ed083f31dd4828204b79b2f56e9f /usr.bin/find
parent775cb4ad60f087a12866d4aec17182865835a874 (diff)
downloadFreeBSD-src-6f9ebfa0c3159b8dd19fa1a837691a7deaaa3842.zip
FreeBSD-src-6f9ebfa0c3159b8dd19fa1a837691a7deaaa3842.tar.gz
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
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/function.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 56d361c..b657099 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -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,
OpenPOWER on IntegriCloud