Module Name: src
Committed By: christos
Date: Mon Feb 1 02:59:33 UTC 2016
Modified Files:
src/sys/fs/msdosfs: direntry.h msdosfs_conv.c msdosfs_vnops.c
Log Message:
We can't depend on dp->d_namlen existing for the parts that are used in
makefs(8).
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/fs/msdosfs/direntry.h
cvs rdiff -u -r1.11 -r1.12 src/sys/fs/msdosfs/msdosfs_conv.c
cvs rdiff -u -r1.94 -r1.95 src/sys/fs/msdosfs/msdosfs_vnops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/fs/msdosfs/direntry.h
diff -u src/sys/fs/msdosfs/direntry.h:1.10 src/sys/fs/msdosfs/direntry.h:1.11
--- src/sys/fs/msdosfs/direntry.h:1.10 Sat Jan 30 04:59:27 2016
+++ src/sys/fs/msdosfs/direntry.h Sun Jan 31 21:59:33 2016
@@ -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 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 */
Index: src/sys/fs/msdosfs/msdosfs_conv.c
diff -u src/sys/fs/msdosfs/msdosfs_conv.c:1.11 src/sys/fs/msdosfs/msdosfs_conv.c:1.12
--- src/sys/fs/msdosfs/msdosfs_conv.c:1.11 Sat Jan 30 04:59:27 2016
+++ src/sys/fs/msdosfs/msdosfs_conv.c Sun Jan 31 21:59:33 2016
@@ -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,
* 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
*/
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
*/
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
* 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;
}
Index: src/sys/fs/msdosfs/msdosfs_vnops.c
diff -u src/sys/fs/msdosfs/msdosfs_vnops.c:1.94 src/sys/fs/msdosfs/msdosfs_vnops.c:1.95
--- src/sys/fs/msdosfs/msdosfs_vnops.c:1.94 Sat Jan 30 04:59:27 2016
+++ src/sys/fs/msdosfs/msdosfs_vnops.c Sun Jan 31 21:59:33 2016
@@ -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) {