We can't depend on dp->d_namlen existing for the parts that are used in

makefs(8).
This commit is contained in:
christos 2016-02-01 02:59:33 +00:00
parent cffe196c42
commit 76530fdb8e
3 changed files with 24 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: direntry.h,v 1.10 2016/01/30 09:59:27 mlelstv Exp $ */
/* $NetBSD: direntry.h,v 1.11 2016/02/01 02:59:33 christos Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -140,7 +140,7 @@ int unix2winfn(const unsigned char *un, int unlen, struct winentry *wep,
int winChkName(const unsigned char *un, int unlen, struct winentry *wep,
int chksum, int utf8);
int win2unixfn(struct winentry *wep, struct dirent *dp, int chksum,
int utf8);
uint16_t *namlen, int utf8);
uint8_t winChksum(uint8_t *name);
int winSlotCnt(const unsigned char *un, int unlen, int utf8);
#endif /* _KERNEL || MAKEFS */

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_conv.c,v 1.11 2016/01/30 09:59:27 mlelstv Exp $ */
/* $NetBSD: msdosfs_conv.c,v 1.12 2016/02/01 02:59:33 christos Exp $ */
/*-
* Copyright (C) 1995, 1997 Wolfgang Solfrank.
@ -62,7 +62,7 @@
#endif
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_conv.c,v 1.11 2016/01/30 09:59:27 mlelstv Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_conv.c,v 1.12 2016/02/01 02:59:33 christos Exp $");
/*
* System include files.
@ -1549,7 +1549,8 @@ winChkName(const u_char *un, int unlen, struct winentry *wep, int chksum, int ut
* Returns the checksum or -1 if impossible
*/
int
win2unixfn(struct winentry *wep, struct dirent *dp, int chksum, int utf8)
win2unixfn(struct winentry *wep, struct dirent *dp, int chksum,
uint16_t *namlen, int utf8)
{
u_int16_t wn[WIN_CHARS], *p;
u_int8_t buf[WIN_CHARS*3];
@ -1564,7 +1565,7 @@ win2unixfn(struct winentry *wep, struct dirent *dp, int chksum, int utf8)
*/
if (wep->weCnt & WIN_LAST) {
chksum = wep->weChksum;
dp->d_namlen = 0;
*namlen = 0;
} else if (chksum != wep->weChksum)
chksum = -1;
if (chksum == -1)
@ -1591,6 +1592,9 @@ win2unixfn(struct winentry *wep, struct dirent *dp, int chksum, int utf8)
*/
len = utf8 ? ucs2utf8str(wn, WIN_CHARS, buf, sizeof(buf)) : ucs2char8str(wn, WIN_CHARS, buf, sizeof(buf));
if (len > sizeof(dp->d_name) - 1)
return -1;
/*
* Prepend name segment to directory entry
*
@ -1602,12 +1606,16 @@ win2unixfn(struct winentry *wep, struct dirent *dp, int chksum, int utf8)
* are silently discarded. This could also end in multiple
* files using the same (truncated) name.
*/
dp->d_namlen += len;
if (dp->d_namlen > sizeof(dp->d_name)-1)
dp->d_namlen = sizeof(dp->d_name)-1;
memmove(&dp->d_name[len], &dp->d_name[0], dp->d_namlen - len);
*namlen += len;
if (*namlen > sizeof(dp->d_name) - 1)
*namlen = sizeof(dp->d_name) - 1;
memmove(&dp->d_name[len], &dp->d_name[0], *namlen - len);
memcpy(dp->d_name, buf, len);
#ifdef __NetBSD__
dp->d_namlen = *namlen;
#endif
return chksum;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vnops.c,v 1.94 2016/01/30 09:59:27 mlelstv Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.95 2016/02/01 02:59:33 christos Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.94 2016/01/30 09:59:27 mlelstv Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.95 2016/02/01 02:59:33 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1394,6 +1394,7 @@ msdosfs_readdir(void *v)
int ncookies = 0, nc = 0;
off_t offset, uio_off;
int chksum = -1;
uint16_t namlen;
#ifdef MSDOSFS_DEBUG
printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
@ -1541,7 +1542,8 @@ msdosfs_readdir(void *v)
if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
continue;
chksum = win2unixfn((struct winentry *)dentp,
dirbuf, chksum, pmp->pm_flags & MSDOSFSMNT_UTF8);
dirbuf, chksum, &namlen,
pmp->pm_flags & MSDOSFSMNT_UTF8);
continue;
}
@ -1584,6 +1586,7 @@ msdosfs_readdir(void *v)
pmp->pm_flags & MSDOSFSMNT_SHORTNAME);
else
dirbuf->d_name[dirbuf->d_namlen] = 0;
namlen = dirbuf->d_namlen;
chksum = -1;
dirbuf->d_reclen = _DIRENT_SIZE(dirbuf);
if (uio->uio_resid < dirbuf->d_reclen) {