svn commit: r352872 - stable/12/sbin/fsck_msdosfs

Xin LI delphij at FreeBSD.org
Sun Sep 29 20:05:49 UTC 2019


Author: delphij
Date: Sun Sep 29 20:05:48 2019
New Revision: 352872
URL: https://svnweb.freebsd.org/changeset/base/352872

Log:
  MFC r351802:
  
  Correct overflow logic in fullpath().
  
  Obtained from:	OpenBSD

Modified:
  stable/12/sbin/fsck_msdosfs/dir.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/fsck_msdosfs/dir.c
==============================================================================
--- stable/12/sbin/fsck_msdosfs/dir.c	Sun Sep 29 18:33:29 2019	(r352871)
+++ stable/12/sbin/fsck_msdosfs/dir.c	Sun Sep 29 20:05:48 2019	(r352872)
@@ -168,20 +168,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-stable-12 mailing list