sbin/fsck_msdosfs: Bring in FreeBSD/Git 9502e5ba (fix fullpath())
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 12 Sep 2019 13:36:55 +0000 (22:36 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 12 Sep 2019 14:58:02 +0000 (23:58 +0900)
sbin/fsck_msdosfs/dir.c

index 4b968ec..3cfea04 100644 (file)
@@ -167,20 +167,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;
 }