Correct overflow logic in fullpath().

Obtained from:	OpenBSD
MFC after:	3 days
This commit is contained in:
Xin LI 2019-09-04 04:44:03 +00:00
parent ecc5b1d156
commit 07282103f5

View File

@ -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;
}