svn commit: r351802 - head/sbin/fsck_msdosfs

Xin LI delphij at FreeBSD.org
Wed Sep 4 04:44:03 UTC 2019


Author: delphij
Date: Wed Sep  4 04:44:03 2019
New Revision: 351802
URL: https://svnweb.freebsd.org/changeset/base/351802

Log:
  Correct overflow logic in fullpath().
  
  Obtained from:	OpenBSD
  MFC after:	3 days

Modified:
  head/sbin/fsck_msdosfs/dir.c

Modified: head/sbin/fsck_msdosfs/dir.c
==============================================================================
--- head/sbin/fsck_msdosfs/dir.c	Wed Sep  4 04:38:31 2019	(r351801)
+++ head/sbin/fsck_msdosfs/dir.c	Wed Sep  4 04:44:03 2019	(r351802)
@@ -169,20 +169,24 @@ fullpath(struct dosDirEntry *dir)
 	char *cp, *np;
 	int nl;
 
-	cp = namebuf + sizeof namebuf - 1;
-	*cp = '\0';
-	do {
+	cp = namebuf + sizeof namebuf;
+	*--cp = '\0';
+
+	for(;;) {
 		np = dir->lname[0] ? dir->lname : dir->name;
 		nl = strlen(np);
-		if ((cp -= nl) <= namebuf + 1)
+		if (cp <= namebuf + 1 + nl) {
+			*--cp = '?';
 			break;
+		}
+		cp -= nl;
 		memcpy(cp, np, nl);
+		dir = dir->parent;
+		if (!dir)
+			break;
 		*--cp = '/';
-	} while ((dir = dir->parent) != NULL);
-	if (dir)
-		*--cp = '?';
-	else
-		cp++;
+	}
+
 	return cp;
 }
 


More information about the svn-src-head mailing list