Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Jan 2014 21:44:05 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r260336 - head/usr.bin/find
Message-ID:  <201401052144.s05Li5oq091675@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Jan  5 21:44:04 2014
New Revision: 260336
URL: http://svnweb.freebsd.org/changeset/base/260336

Log:
  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

Modified:
  head/usr.bin/find/function.c

Modified: head/usr.bin/find/function.c
==============================================================================
--- head/usr.bin/find/function.c	Sun Jan  5 21:35:07 2014	(r260335)
+++ head/usr.bin/find/function.c	Sun Jan  5 21:44:04 2014	(r260336)
@@ -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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401052144.s05Li5oq091675>