diff options
| author | Kristof Provost <kp@FreeBSD.org> | 2016-04-26 20:36:32 +0000 |
|---|---|---|
| committer | Kristof Provost <kp@FreeBSD.org> | 2016-04-26 20:36:32 +0000 |
| commit | 66527f742bfb1f358bc10eadffdb9cc1fdfa93ac (patch) | |
| tree | d132704f71165ced5307bf8367819537a4ce2956 /sys/fs | |
| parent | dcbee68850de463f4e89a40f715135fa76a97e64 (diff) | |
Notes
Diffstat (limited to 'sys/fs')
| -rw-r--r-- | sys/fs/msdosfs/direntry.h | 2 | ||||
| -rw-r--r-- | sys/fs/msdosfs/msdosfs_conv.c | 30 |
2 files changed, 23 insertions, 9 deletions
diff --git a/sys/fs/msdosfs/direntry.h b/sys/fs/msdosfs/direntry.h index 86b6fbb099f2..facec3095dd3 100644 --- a/sys/fs/msdosfs/direntry.h +++ b/sys/fs/msdosfs/direntry.h @@ -145,7 +145,7 @@ struct msdosfsmount; char *mbnambuf_flush(struct mbnambuf *nbp, struct dirent *dp); void mbnambuf_init(struct mbnambuf *nbp); -void mbnambuf_write(struct mbnambuf *nbp, char *name, int id); +int mbnambuf_write(struct mbnambuf *nbp, char *name, int id); int dos2unixfn(u_char dn[11], u_char *un, int lower, struct msdosfsmount *pmp); int unix2dosfn(const u_char *un, u_char dn[12], size_t unlen, u_int gen, diff --git a/sys/fs/msdosfs/msdosfs_conv.c b/sys/fs/msdosfs/msdosfs_conv.c index efed30ca50fc..396df9ecc0bd 100644 --- a/sys/fs/msdosfs/msdosfs_conv.c +++ b/sys/fs/msdosfs/msdosfs_conv.c @@ -658,7 +658,9 @@ win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum, switch (code) { case 0: *np = '\0'; - mbnambuf_write(nbp, name, (wep->weCnt & WIN_CNT) - 1); + if (mbnambuf_write(nbp, name, + (wep->weCnt & WIN_CNT) - 1) != 0) + return -1; return chksum; case '/': *np = '\0'; @@ -676,7 +678,9 @@ win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum, switch (code) { case 0: *np = '\0'; - mbnambuf_write(nbp, name, (wep->weCnt & WIN_CNT) - 1); + if (mbnambuf_write(nbp, name, + (wep->weCnt & WIN_CNT) - 1) != 0) + return -1; return chksum; case '/': *np = '\0'; @@ -694,7 +698,9 @@ win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum, switch (code) { case 0: *np = '\0'; - mbnambuf_write(nbp, name, (wep->weCnt & WIN_CNT) - 1); + if (mbnambuf_write(nbp, name, + (wep->weCnt & WIN_CNT) - 1) != 0) + return -1; return chksum; case '/': *np = '\0'; @@ -708,7 +714,8 @@ win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum, cp += 2; } *np = '\0'; - mbnambuf_write(nbp, name, (wep->weCnt & WIN_CNT) - 1); + if (mbnambuf_write(nbp, name, (wep->weCnt & WIN_CNT) - 1) != 0) + return -1; return chksum; } @@ -1005,7 +1012,7 @@ mbnambuf_init(struct mbnambuf *nbp) * This only penalizes portions of substrings that contain more than * WIN_CHARS bytes when they are first encountered. */ -void +int mbnambuf_write(struct mbnambuf *nbp, char *name, int id) { char *slot; @@ -1016,7 +1023,7 @@ mbnambuf_write(struct mbnambuf *nbp, char *name, int id) printf("msdosfs: non-decreasing id: id %d, last id %d\n", id, nbp->nb_last_id); #endif - return; + return (EINVAL); } /* Will store this substring in a WIN_CHARS-aligned slot. */ @@ -1027,17 +1034,24 @@ mbnambuf_write(struct mbnambuf *nbp, char *name, int id) #ifdef MSDOSFS_DEBUG printf("msdosfs: file name length %zu too large\n", newlen); #endif - return; + return (ENAMETOOLONG); } /* Shift suffix upwards by the amount length exceeds WIN_CHARS. */ - if (count > WIN_CHARS && nbp->nb_len != 0) + if (count > WIN_CHARS && nbp->nb_len != 0) { + if ((id * WIN_CHARS + count + nbp->nb_len) > + sizeof(nbp->nb_buf)) + return (ENAMETOOLONG); + bcopy(slot + WIN_CHARS, slot + count, nbp->nb_len); + } /* Copy in the substring to its slot and update length so far. */ bcopy(name, slot, count); nbp->nb_len = newlen; nbp->nb_last_id = id; + + return (0); } /* |
