stack police: don't allocate statvfs on the stack.

This commit is contained in:
christos 2006-06-12 00:46:50 +00:00
parent 155721b1be
commit 48432186cb
1 changed files with 26 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls_20.c,v 1.8 2006/05/14 21:24:49 elad Exp $ */
/* $NetBSD: vfs_syscalls_20.c,v 1.9 2006/06/12 00:46:50 christos Exp $ */
/*
* Copyright (c) 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.8 2006/05/14 21:24:49 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.9 2006/06/12 00:46:50 christos Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_43.h"
@ -186,18 +186,20 @@ compat_20_sys_fstatfs(l, v, retval)
struct proc *p = l->l_proc;
struct file *fp;
struct mount *mp;
struct statvfs sbuf;
struct statvfs *sbuf;
int error;
/* getvnode() will use the descriptor for us */
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
if ((error = dostatvfs(mp, &sbuf, l, 0, 1)) != 0)
sbuf = malloc(sizeof(*sbuf), M_TEMP, M_WAITOK);
if ((error = dostatvfs(mp, sbuf, l, 0, 1)) != 0)
goto out;
error = vfs2fs(SCARG(uap, buf), &sbuf);
error = vfs2fs(SCARG(uap, buf), sbuf);
out:
FILE_UNUSE(fp, l);
free(sbuf, M_TEMP);
return error;
}
@ -218,7 +220,7 @@ compat_20_sys_getfsstat(l, v, retval)
} */ *uap = v;
int root = 0;
struct mount *mp, *nmp;
struct statvfs sbuf;
struct statvfs *sbuf;
struct statfs12 *sfsp;
size_t count, maxcount;
int error = 0;
@ -227,6 +229,7 @@ compat_20_sys_getfsstat(l, v, retval)
sfsp = SCARG(uap, buf);
simple_lock(&mountlist_slock);
count = 0;
sbuf = malloc(sizeof(*sbuf), M_TEMP, M_WAITOK);
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
mp = nmp) {
if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
@ -234,20 +237,20 @@ compat_20_sys_getfsstat(l, v, retval)
continue;
}
if (sfsp && count < maxcount) {
error = dostatvfs(mp, &sbuf, l, SCARG(uap, flags), 0);
error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 0);
if (error) {
simple_lock(&mountlist_slock);
nmp = CIRCLEQ_NEXT(mp, mnt_list);
vfs_unbusy(mp);
continue;
}
error = vfs2fs(sfsp, &sbuf);
error = vfs2fs(sfsp, sbuf);
if (error) {
vfs_unbusy(mp);
return (error);
goto out;
}
sfsp++;
root |= strcmp(sbuf.f_mntonname, "/") == 0;
root |= strcmp(sbuf->f_mntonname, "/") == 0;
}
count++;
simple_lock(&mountlist_slock);
@ -259,17 +262,19 @@ compat_20_sys_getfsstat(l, v, retval)
/*
* fake a root entry
*/
if ((error = dostatvfs(l->l_proc->p_cwdi->cwdi_rdir->v_mount, &sbuf, l,
if ((error = dostatvfs(l->l_proc->p_cwdi->cwdi_rdir->v_mount, sbuf, l,
SCARG(uap, flags), 1)) != 0)
return error;
goto out;
if (sfsp)
error = vfs2fs(sfsp, &sbuf);
error = vfs2fs(sfsp, sbuf);
count++;
}
if (sfsp && count > maxcount)
*retval = maxcount;
else
*retval = count;
out:
free(sbuf, M_TEMP);
return error;
}
@ -284,7 +289,7 @@ compat_20_sys_fhstatfs(l, v, retval)
syscallarg(struct statfs12 *) buf;
} */ *uap = v;
struct proc *p = l->l_proc;
struct statvfs sbuf;
struct statvfs *sbuf;
fhandle_t fh;
struct mount *mp;
struct vnode *vp;
@ -305,7 +310,11 @@ compat_20_sys_fhstatfs(l, v, retval)
return (error);
mp = vp->v_mount;
vput(vp);
if ((error = VFS_STATVFS(mp, &sbuf, l)) != 0)
return (error);
return vfs2fs(SCARG(uap, buf), &sbuf);
sbuf = malloc(sizeof(*sbuf), M_TEMP, M_WAITOK);
if ((error = VFS_STATVFS(mp, sbuf, l)) != 0)
goto out;
error = vfs2fs(SCARG(uap, buf), sbuf);
out:
free(sbuf, M_TEMP);
return error;
}