Module Name: src
Committed By: snj
Date: Sat Feb 14 08:11:07 UTC 2015
Modified Files:
src/sys/fs/ntfs [netbsd-7]: ntfs_subr.c ntfs_vfsops.c
Log Message:
Pull up following revision(s) (requested by maxv in ticket #513):
sys/fs/ntfs/ntfs_vfsops.c: revision 1.99, 1.100
sys/fs/ntfs/ntfs_subr.c: revision 1.59
Ensure bps != 0 to prevent a division by zero. Zero byte per sector makes
no sense.
--
Prevent another division by zero in ntfs_loadntnode() by ensuring
spc != 0.
--
Fix a node leak.
Sent on tech-kern@, tested by martin@
To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.51.8.1 src/sys/fs/ntfs/ntfs_subr.c
cvs rdiff -u -r1.94 -r1.94.2.1 src/sys/fs/ntfs/ntfs_vfsops.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/ntfs/ntfs_subr.c
diff -u src/sys/fs/ntfs/ntfs_subr.c:1.51 src/sys/fs/ntfs/ntfs_subr.c:1.51.8.1
--- src/sys/fs/ntfs/ntfs_subr.c:1.51 Fri Jun 28 17:13:34 2013
+++ src/sys/fs/ntfs/ntfs_subr.c Sat Feb 14 08:11:07 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs_subr.c,v 1.51 2013/06/28 17:13:34 matt Exp $ */
+/* $NetBSD: ntfs_subr.c,v 1.51.8.1 2015/02/14 08:11:07 snj Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko ([email protected])
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.51 2013/06/28 17:13:34 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ntfs_subr.c,v 1.51.8.1 2015/02/14 08:11:07 snj Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -865,9 +865,9 @@ ntfs_ntlookupfile(
{
struct fnode *fp = VTOF(vp);
struct ntnode *ip = FTONT(fp);
- struct ntvattr *vap; /* Root attribute */
+ struct ntvattr *vap = NULL; /* Root attribute */
cn_t cn = 0; /* VCN in current attribute */
- void * rdbuf; /* Buffer to read directory's blocks */
+ void * rdbuf = NULL; /* Buffer to read directory's blocks */
u_int32_t blsize;
u_int32_t rdsize; /* Length of data to read from current block */
struct attr_indexentry *iep;
@@ -887,8 +887,10 @@ ntfs_ntlookupfile(
return (error);
error = ntfs_ntvattrget(ntmp, ip, NTFS_A_INDXROOT, "$I30", 0, &vap);
- if (error || (vap->va_flag & NTFS_AF_INRUN))
- return (ENOTDIR);
+ if (error || (vap->va_flag & NTFS_AF_INRUN)) {
+ error = ENOTDIR;
+ goto fail;
+ }
/*
* Divide file name into: foofilefoofilefoofile[:attrspec]
@@ -1114,9 +1116,11 @@ fail:
free(tctx, M_TEMP);
}
}
- ntfs_ntvattrrele(vap);
+ if (vap)
+ ntfs_ntvattrrele(vap);
+ if (rdbuf)
+ free(rdbuf, M_TEMP);
ntfs_ntput(ip);
- free(rdbuf, M_TEMP);
return (error);
}
@@ -1182,8 +1186,10 @@ ntfs_ntreaddir(
return (error);
error = ntfs_ntvattrget(ntmp, ip, NTFS_A_INDXROOT, "$I30", 0, &vap);
- if (error)
- return (ENOTDIR);
+ if (error) {
+ error = ENOTDIR;
+ goto fail;
+ }
if (fp->f_dirblbuf == NULL) {
fp->f_dirblsz = vap->va_a_iroot->ir_size;
Index: src/sys/fs/ntfs/ntfs_vfsops.c
diff -u src/sys/fs/ntfs/ntfs_vfsops.c:1.94 src/sys/fs/ntfs/ntfs_vfsops.c:1.94.2.1
--- src/sys/fs/ntfs/ntfs_vfsops.c:1.94 Wed Apr 16 18:55:18 2014
+++ src/sys/fs/ntfs/ntfs_vfsops.c Sat Feb 14 08:11:07 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ntfs_vfsops.c,v 1.94 2014/04/16 18:55:18 maxv Exp $ */
+/* $NetBSD: ntfs_vfsops.c,v 1.94.2.1 2015/02/14 08:11:07 snj Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.94 2014/04/16 18:55:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.94.2.1 2015/02/14 08:11:07 snj Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -331,11 +331,22 @@ ntfs_mountfs(struct vnode *devvp, struct
brelse( bp , 0 );
bp = NULL;
+ /* Sanity checks. XXX: More checks are probably needed. */
if (strncmp(ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
error = EINVAL;
dprintf(("ntfs_mountfs: invalid boot block\n"));
goto out;
}
+ if (ntmp->ntm_bps == 0) {
+ error = EINVAL;
+ dprintf(("ntfs_mountfs: invalid bytes per sector\n"));
+ goto out;
+ }
+ if (ntmp->ntm_spc == 0) {
+ error = EINVAL;
+ dprintf(("ntfs_mountfs: invalid sectors per cluster\n"));
+ goto out;
+ }
{
int8_t cpr = ntmp->ntm_mftrecsz;