stack police: don't allocate statvfs on the stack.
This commit is contained in:
parent
54cd6fafa8
commit
d5ba7564d8
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: svr4_misc.c,v 1.116 2006/03/01 12:38:12 yamt Exp $ */
|
||||
/* $NetBSD: svr4_misc.c,v 1.117 2006/06/09 23:24:24 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
||||
|
@ -44,7 +44,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.116 2006/03/01 12:38:12 yamt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.117 2006/06/09 23:24:24 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -114,6 +114,8 @@ static void bsd_statvfs_to_svr4_statvfs __P((const struct statvfs *,
|
|||
struct svr4_statvfs *));
|
||||
static void bsd_statvfs_to_svr4_statvfs64 __P((const struct statvfs *,
|
||||
struct svr4_statvfs64 *));
|
||||
static int svr4_copystatvfs64(struct svr4_statvfs64 *, const struct statvfs *);
|
||||
static int svr4_copystatvfs(struct svr4_statvfs *, const struct statvfs *);
|
||||
#define svr4_pfind(pid) p_find((pid), PFIND_UNLOCK | PFIND_ZOMBIE)
|
||||
|
||||
static int svr4_mknod __P((struct lwp *, register_t *, const char *,
|
||||
|
@ -1228,6 +1230,44 @@ svr4_sys_waitsys(l, v, retval)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
svr4_copystatvfs64(struct svr4_statvfs64 *sufs, const struct statvfs *bufs)
|
||||
{
|
||||
struct svr4_statvfs64 *skfs = malloc(sizeof(*skfs), M_TEMP, M_WAITOK);
|
||||
struct statvfs *bkfs = malloc(sizeof(*bkfs), M_TEMP, M_WAITOK);
|
||||
int error;
|
||||
|
||||
if ((error = copyin(sufs, bkfs, sizeof(*bkfs))) != 0)
|
||||
goto out;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs64(bkfs, skfs);
|
||||
|
||||
error = copyout(skfs, sufs, sizeof(*skfs));
|
||||
out:
|
||||
free(skfs, M_TEMP);
|
||||
free(bkfs, M_TEMP);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
svr4_copystatvfs(struct svr4_statvfs *sufs, const struct statvfs *bufs)
|
||||
{
|
||||
struct svr4_statvfs *skfs = malloc(sizeof(*skfs), M_TEMP, M_WAITOK);
|
||||
struct statvfs *bkfs = malloc(sizeof(*bkfs), M_TEMP, M_WAITOK);
|
||||
int error;
|
||||
|
||||
if ((error = copyin(bufs, bkfs, sizeof(*bkfs))) != 0)
|
||||
goto out;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs(bkfs, skfs);
|
||||
|
||||
error = copyout(skfs, sufs, sizeof(*skfs));
|
||||
out:
|
||||
free(skfs, M_TEMP);
|
||||
free(bkfs, M_TEMP);
|
||||
return error;
|
||||
}
|
||||
|
||||
static void
|
||||
bsd_statvfs_to_svr4_statvfs(const struct statvfs *bfs,
|
||||
struct svr4_statvfs *sfs)
|
||||
|
@ -1289,8 +1329,6 @@ svr4_sys_statvfs(l, v, retval)
|
|||
struct proc *p = l->l_proc;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_statvfs sfs;
|
||||
int error;
|
||||
|
||||
CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
|
||||
|
@ -1301,12 +1339,7 @@ svr4_sys_statvfs(l, v, retval)
|
|||
if ((error = sys_statvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1321,8 +1354,6 @@ svr4_sys_fstatvfs(l, v, retval)
|
|||
struct sys_fstatvfs1_args fs_args;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_statvfs sfs;
|
||||
int error;
|
||||
|
||||
SCARG(&fs_args, fd) = SCARG(uap, fd);
|
||||
|
@ -1332,12 +1363,7 @@ svr4_sys_fstatvfs(l, v, retval)
|
|||
if ((error = sys_fstatvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1352,8 +1378,6 @@ svr4_sys_statvfs64(l, v, retval)
|
|||
struct sys_statvfs1_args fs_args;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_statvfs64 sfs;
|
||||
int error;
|
||||
|
||||
CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
|
||||
|
@ -1364,12 +1388,7 @@ svr4_sys_statvfs64(l, v, retval)
|
|||
if ((error = sys_statvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs64(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs64(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1384,8 +1403,6 @@ svr4_sys_fstatvfs64(l, v, retval)
|
|||
struct sys_fstatvfs1_args fs_args;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_statvfs64 sfs;
|
||||
int error;
|
||||
|
||||
SCARG(&fs_args, fd) = SCARG(uap, fd);
|
||||
|
@ -1395,15 +1412,11 @@ svr4_sys_fstatvfs64(l, v, retval)
|
|||
if ((error = sys_fstatvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs64(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs64(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
svr4_sys_alarm(l, v, retval)
|
||||
struct lwp *l;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: svr4_32_misc.c,v 1.35 2006/03/01 12:38:12 yamt Exp $ */
|
||||
/* $NetBSD: svr4_32_misc.c,v 1.36 2006/06/09 23:24:25 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
||||
|
@ -44,7 +44,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.35 2006/03/01 12:38:12 yamt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.36 2006/06/09 23:24:25 christos Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -114,6 +114,8 @@ static void bsd_statvfs_to_svr4_32_statvfs __P((const struct statvfs *,
|
|||
struct svr4_32_statvfs *));
|
||||
static void bsd_statvfs_to_svr4_32_statvfs64 __P((const struct statvfs *,
|
||||
struct svr4_32_statvfs64 *));
|
||||
static int svr4_copystatvfs64(struct svr4_32_statvfs64 *, const struct statvfs *);
|
||||
static int svr4_copystatvfs(struct svr4_32_statvfs *, const struct statvfs *);
|
||||
#define svr4_32_pfind(pid) p_find((pid), PFIND_UNLOCK | PFIND_ZOMBIE)
|
||||
|
||||
static int svr4_32_mknod __P((struct lwp *, register_t *, const char *,
|
||||
|
@ -1245,6 +1247,43 @@ svr4_32_sys_waitsys(l, v, retval)
|
|||
SCARG(uap, info));
|
||||
}
|
||||
|
||||
static int
|
||||
svr4_copystatvfs64(struct svr4_32_statvfs64 *sufs, const struct statvfs *bufs)
|
||||
{
|
||||
struct svr4_statvfs64 *skfs = malloc(sizeof(*skfs), M_TEMP, M_WAITOK);
|
||||
struct statvfs *bkfs = malloc(sizeof(*bkfs), M_TEMP, M_WAITOK);
|
||||
int error;
|
||||
|
||||
if ((error = copyin(sufs, bkfs, sizeof(*bkfs))) != 0)
|
||||
goto out;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs64(bkfs, skfs);
|
||||
|
||||
error = copyout(skfs, sufs, sizeof(*skfs));
|
||||
out:
|
||||
free(skfs, M_TEMP);
|
||||
free(bkfs, M_TEMP);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int
|
||||
svr4_copystatvfs(struct svr4_32_statvfs *sufs, const struct statvfs *bufs)
|
||||
{
|
||||
struct svr4_statvfs *skfs = malloc(sizeof(*skfs), M_TEMP, M_WAITOK);
|
||||
struct statvfs *bkfs = malloc(sizeof(*bkfs), M_TEMP, M_WAITOK);
|
||||
int error;
|
||||
|
||||
if ((error = copyin(bufs, bkfs, sizeof(*bkfs))) != 0)
|
||||
goto out;
|
||||
|
||||
bsd_statvfs_to_svr4_statvfs(bkfs, skfs);
|
||||
|
||||
error = copyout(skfs, sufs, sizeof(*skfs));
|
||||
out:
|
||||
free(skfs, M_TEMP);
|
||||
free(bkfs, M_TEMP);
|
||||
return error;
|
||||
}
|
||||
|
||||
static void
|
||||
bsd_statvfs_to_svr4_32_statvfs(bfs, sfs)
|
||||
|
@ -1309,8 +1348,6 @@ svr4_32_sys_statvfs(l, v, retval)
|
|||
struct sys_statvfs1_args fs_args;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_32_statvfs sfs;
|
||||
int error;
|
||||
|
||||
SCARG(&fs_args, path) = (caddr_t)(u_long)SCARG(uap, path);
|
||||
|
@ -1321,12 +1358,7 @@ svr4_32_sys_statvfs(l, v, retval)
|
|||
if ((error = sys_statvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_32_statvfs(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1341,8 +1373,6 @@ svr4_32_sys_fstatvfs(l, v, retval)
|
|||
struct sys_fstatvfs1_args fs_args;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_32_statvfs sfs;
|
||||
int error;
|
||||
|
||||
SCARG(&fs_args, fd) = SCARG(uap, fd);
|
||||
|
@ -1352,12 +1382,7 @@ svr4_32_sys_fstatvfs(l, v, retval)
|
|||
if ((error = sys_fstatvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_32_statvfs(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1372,8 +1397,6 @@ svr4_32_sys_statvfs64(l, v, retval)
|
|||
struct proc *p = l->l_proc;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_32_statvfs64 sfs;
|
||||
int error;
|
||||
|
||||
SCARG(&fs_args, path) = (caddr_t)(u_long)SCARG(uap, path);
|
||||
|
@ -1384,12 +1407,7 @@ svr4_32_sys_statvfs64(l, v, retval)
|
|||
if ((error = sys_statvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_32_statvfs64(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs64(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1404,8 +1422,6 @@ svr4_32_sys_fstatvfs64(l, v, retval)
|
|||
struct sys_fstatvfs1_args fs_args;
|
||||
caddr_t sg = stackgap_init(p, 0);
|
||||
struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
|
||||
struct statvfs bfs;
|
||||
struct svr4_32_statvfs64 sfs;
|
||||
int error;
|
||||
|
||||
SCARG(&fs_args, fd) = SCARG(uap, fd);
|
||||
|
@ -1415,12 +1431,7 @@ svr4_32_sys_fstatvfs64(l, v, retval)
|
|||
if ((error = sys_fstatvfs1(l, &fs_args, retval)) != 0)
|
||||
return error;
|
||||
|
||||
if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
|
||||
return error;
|
||||
|
||||
bsd_statvfs_to_svr4_32_statvfs64(&bfs, &sfs);
|
||||
|
||||
return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
|
||||
return svr4_copystatvfs64(SCARG(uap, fs), fs);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue