don't allocate too much stuff on the stack.

This commit is contained in:
christos 2006-06-20 03:20:44 +00:00
parent 8dc1cf5155
commit 709b2e6f55
2 changed files with 35 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cgd.c,v 1.35 2006/05/14 21:42:26 elad Exp $ */
/* $NetBSD: cgd.c,v 1.36 2006/06/20 03:20:44 christos Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.35 2006/05/14 21:42:26 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.36 2006/06/20 03:20:44 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -501,16 +501,18 @@ cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l)
int ret;
int keybytes; /* key length in bytes */
const char *cp;
char inbuf[MAX_KEYSIZE];
char *inbuf;
cp = ci->ci_disk;
if ((ret = dk_lookup(cp, l, &vp)) != 0)
return ret;
inbuf = malloc(MAX_KEYSIZE, M_TEMP, M_WAITOK);
if ((ret = cgdinit(cs, cp, vp, l)) != 0)
goto bail;
memset(inbuf, 0x0, sizeof(inbuf));
(void)memset(inbuf, 0, MAX_KEYSIZE);
ret = copyinstr(ci->ci_alg, inbuf, 256, NULL);
if (ret)
goto bail;
@ -521,8 +523,8 @@ cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l)
}
/* right now we only support encblkno, so hard-code it */
memset(inbuf, 0x0, sizeof(inbuf));
ret = copyinstr(ci->ci_ivmethod, inbuf, sizeof(inbuf), NULL);
(void)memset(inbuf, 0, sizeof(inbuf));
ret = copyinstr(ci->ci_ivmethod, inbuf, MAX_KEYSIZE, NULL);
if (ret)
goto bail;
if (strcmp("encblkno", inbuf)) {
@ -535,7 +537,7 @@ cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l)
ret = EINVAL;
goto bail;
}
memset(inbuf, 0x0, sizeof(inbuf));
(void)memset(inbuf, 0, MAX_KEYSIZE);
ret = copyin(ci->ci_key, inbuf, keybytes);
if (ret)
goto bail;
@ -544,12 +546,13 @@ cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l)
cs->sc_cdata.cf_mode = CGD_CIPHER_CBC_ENCBLKNO;
cs->sc_cdata.cf_priv = cs->sc_cfuncs->cf_init(ci->ci_keylen, inbuf,
&cs->sc_cdata.cf_blocksize);
memset(inbuf, 0x0, sizeof(inbuf));
(void)memset(inbuf, 0, MAX_KEYSIZE);
if (!cs->sc_cdata.cf_priv) {
printf("cgd: unable to initialize cipher\n");
ret = EINVAL; /* XXX is this the right error? */
goto bail;
}
free(inbuf, M_TEMP);
bufq_alloc(&cs->sc_dksc.sc_bufq, "fcfs", 0);
@ -570,6 +573,7 @@ cgd_ioctl_set(struct cgd_softc *cs, void *data, struct lwp *l)
return 0;
bail:
free(inbuf, M_TEMP);
(void)vn_close(vp, FREAD|FWRITE, l->l_proc->p_cred, l);
return ret;
}
@ -610,12 +614,13 @@ cgdinit(struct cgd_softc *cs, const char *cpath, struct vnode *vp,
size_t size;
int maxsecsize = 0;
int ret;
char tmppath[MAXPATHLEN];
char *tmppath;
cs->sc_dksc.sc_size = 0;
cs->sc_tvn = vp;
cs->sc_tpath = NULL;
memset(tmppath, 0x0, sizeof(tmppath));
tmppath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
ret = copyinstr(cpath, tmppath, MAXPATHLEN, &cs->sc_tpathlen);
if (ret)
goto bail;
@ -656,6 +661,7 @@ cgdinit(struct cgd_softc *cs, const char *cpath, struct vnode *vp,
pdg->pdg_ncylinders = cs->sc_dksc.sc_size / pdg->pdg_nsectors;
bail:
free(tmppath, M_TEMP);
if (ret && cs->sc_tpath)
free(cs->sc_tpath, M_DEVBUF);
return ret;

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_sysctl.c,v 1.72 2006/06/17 06:54:58 yamt Exp $ */
/* $NetBSD: init_sysctl.c,v 1.73 2006/06/20 03:21:03 christos Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.72 2006/06/17 06:54:58 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.73 2006/06/20 03:21:03 christos Exp $");
#include "opt_sysv.h"
#include "opt_multiprocessor.h"
@ -2140,8 +2140,8 @@ fill_file(struct kinfo_file *kp, const struct file *fp, struct proc *p, int i)
static int
sysctl_doeproc(SYSCTLFN_ARGS)
{
struct eproc eproc;
struct kinfo_proc2 kproc2;
struct eproc *eproc;
struct kinfo_proc2 *kproc2;
struct kinfo_proc *dp;
struct proc *p;
const struct proclist_desc *pd;
@ -2179,6 +2179,8 @@ sysctl_doeproc(SYSCTLFN_ARGS)
elem_count = name[3];
}
kproc2 = malloc(sizeof(*kproc2), M_TEMP, M_WAITOK);
eproc = malloc(sizeof(*eproc), M_TEMP, M_WAITOK);
proclist_lock_read();
pd = proclists;
@ -2261,13 +2263,13 @@ again:
}
if (type == KERN_PROC) {
if (buflen >= sizeof(struct kinfo_proc)) {
fill_eproc(p, &eproc);
fill_eproc(p, eproc);
error = copyout(p, &dp->kp_proc,
sizeof(struct proc));
if (error)
goto cleanup;
error = copyout(&eproc, &dp->kp_eproc,
sizeof(eproc));
error = copyout(eproc, &dp->kp_eproc,
sizeof(*eproc));
if (error)
goto cleanup;
dp++;
@ -2276,13 +2278,13 @@ again:
needed += sizeof(struct kinfo_proc);
} else { /* KERN_PROC2 */
if (buflen >= elem_size && elem_count > 0) {
fill_kproc2(p, &kproc2);
fill_kproc2(p, kproc2);
/*
* Copy out elem_size, but not larger than
* the size of a struct kinfo_proc2.
*/
error = copyout(&kproc2, dp2,
min(sizeof(kproc2), elem_size));
error = copyout(kproc2, dp2,
min(sizeof(*kproc2), elem_size));
if (error)
goto cleanup;
dp2 += elem_size;
@ -2302,8 +2304,10 @@ again:
*oldlenp = (char *)dp - where;
else
*oldlenp = dp2 - where;
if (needed > *oldlenp)
return (ENOMEM);
if (needed > *oldlenp) {
error = ENOMEM;
goto out;
}
} else {
needed += KERN_PROCSLOP;
*oldlenp = needed;
@ -2311,6 +2315,9 @@ again:
return (0);
cleanup:
proclist_unlock_read();
out:
free(kproc2, M_TEMP);
free(eproc, M_TEMP);
return (error);
}