diff options
author | Xin LI <delphij@FreeBSD.org> | 2019-09-04 04:44:03 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2019-09-04 04:44:03 +0000 |
commit | 07282103f558b761db70209c5efc2fd1fb705384 (patch) | |
tree | eabc6b0184714b7e6565727d57321f908118e0e2 | |
parent | ecc5b1d156339cde3e2a0b5a5a32d26b7d375432 (diff) | |
download | src-07282103f558b761db70209c5efc2fd1fb705384.tar.gz src-07282103f558b761db70209c5efc2fd1fb705384.zip |
Correct overflow logic in fullpath().
Obtained from: OpenBSD
MFC after: 3 days
Notes
Notes:
svn path=/head/; revision=351802
-rw-r--r-- | sbin/fsck_msdosfs/dir.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/sbin/fsck_msdosfs/dir.c b/sbin/fsck_msdosfs/dir.c index 191ff49ccd81..2163db049fac 100644 --- a/sbin/fsck_msdosfs/dir.c +++ b/sbin/fsck_msdosfs/dir.c @@ -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; } |