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;
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to