for some random places, use PNBUF_GET/PUT rather than
- on-stack buffer - malloc(MAXPATHLEN)
This commit is contained in:
parent
77e0dba33e
commit
5a3e361753
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: exec_elf32.c,v 1.108 2005/12/11 12:24:29 christos Exp $ */
|
||||
/* $NetBSD: exec_elf32.c,v 1.109 2006/02/04 12:09:50 yamt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
|
||||
|
@ -64,7 +64,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.108 2005/12/11 12:24:29 christos Exp $");
|
||||
__KERNEL_RCSID(1, "$NetBSD: exec_elf32.c,v 1.109 2006/02/04 12:09:50 yamt Exp $");
|
||||
|
||||
/* If not included by exec_elf64.c, ELFSIZE won't be defined. */
|
||||
#ifndef ELFSIZE
|
||||
|
@ -604,7 +604,7 @@ exec_elf_makecmds(struct lwp *l, struct exec_package *epp)
|
|||
if (pp->p_type == PT_INTERP) {
|
||||
if (pp->p_filesz >= MAXPATHLEN)
|
||||
goto bad;
|
||||
MALLOC(interp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
|
||||
interp = PNBUF_GET();
|
||||
interp[0] = '\0';
|
||||
if ((error = exec_read_from(l, epp->ep_vp,
|
||||
pp->p_offset, interp, pp->p_filesz)) != 0)
|
||||
|
@ -718,7 +718,7 @@ exec_elf_makecmds(struct lwp *l, struct exec_package *epp)
|
|||
|
||||
epp->ep_emul_arg = ap;
|
||||
|
||||
FREE(interp, M_TEMP);
|
||||
PNBUF_PUT(interp);
|
||||
} else
|
||||
epp->ep_entry = eh->e_entry;
|
||||
|
||||
|
@ -732,7 +732,7 @@ exec_elf_makecmds(struct lwp *l, struct exec_package *epp)
|
|||
|
||||
bad:
|
||||
if (interp)
|
||||
FREE(interp, M_TEMP);
|
||||
PNBUF_PUT(interp);
|
||||
free(ph, M_TEMP);
|
||||
kill_vmcmds(&epp->ep_vmcmds);
|
||||
return ENOEXEC;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: init_sysctl.c,v 1.61 2006/02/02 17:48:51 elad Exp $ */
|
||||
/* $NetBSD: init_sysctl.c,v 1.62 2006/02/04 12:09:50 yamt 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.61 2006/02/02 17:48:51 elad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.62 2006/02/04 12:09:50 yamt Exp $");
|
||||
|
||||
#include "opt_sysv.h"
|
||||
#include "opt_multiprocessor.h"
|
||||
|
@ -1450,26 +1450,31 @@ static int
|
|||
sysctl_kern_defcorename(SYSCTLFN_ARGS)
|
||||
{
|
||||
int error;
|
||||
char newcorename[MAXPATHLEN];
|
||||
char *newcorename;
|
||||
struct sysctlnode node;
|
||||
|
||||
newcorename = PNBUF_GET();
|
||||
node = *rnode;
|
||||
node.sysctl_data = &newcorename[0];
|
||||
memcpy(node.sysctl_data, rnode->sysctl_data, MAXPATHLEN);
|
||||
error = sysctl_lookup(SYSCTLFN_CALL(&node));
|
||||
if (error || newp == NULL)
|
||||
return (error);
|
||||
if (error || newp == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* when sysctl_lookup() deals with a string, it's guaranteed
|
||||
* to come back nul terminated. so there. :)
|
||||
*/
|
||||
if (strlen(newcorename) == 0)
|
||||
return (EINVAL);
|
||||
|
||||
memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
|
||||
|
||||
return (0);
|
||||
if (strlen(newcorename) == 0) {
|
||||
error = EINVAL;
|
||||
} else {
|
||||
memcpy(rnode->sysctl_data, node.sysctl_data, MAXPATHLEN);
|
||||
error = 0;
|
||||
}
|
||||
done:
|
||||
PNBUF_PUT(newcorename);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_resource.c,v 1.99 2005/12/11 12:24:29 christos Exp $ */
|
||||
/* $NetBSD: kern_resource.c,v 1.100 2006/02/04 12:09:50 yamt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1991, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.99 2005/12/11 12:24:29 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.100 2006/02/04 12:09:50 yamt Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.99 2005/12/11 12:24:29 christos
|
|||
#include <sys/file.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/pool.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
@ -611,7 +612,8 @@ sysctl_proc_corename(SYSCTLFN_ARGS)
|
|||
struct proc *ptmp, *p;
|
||||
struct plimit *lim;
|
||||
int error = 0, len;
|
||||
char cname[MAXPATHLEN], *tmp;
|
||||
char *cname;
|
||||
char *tmp;
|
||||
struct sysctlnode node;
|
||||
|
||||
/*
|
||||
|
@ -630,11 +632,12 @@ sysctl_proc_corename(SYSCTLFN_ARGS)
|
|||
if (error)
|
||||
return (error);
|
||||
|
||||
cname = PNBUF_GET();
|
||||
/*
|
||||
* let them modify a temporary copy of the core name
|
||||
*/
|
||||
node = *rnode;
|
||||
strlcpy(cname, ptmp->p_limit->pl_corename, sizeof(cname));
|
||||
strlcpy(cname, ptmp->p_limit->pl_corename, MAXPATHLEN);
|
||||
node.sysctl_data = cname;
|
||||
error = sysctl_lookup(SYSCTLFN_CALL(&node));
|
||||
|
||||
|
@ -643,8 +646,9 @@ sysctl_proc_corename(SYSCTLFN_ARGS)
|
|||
* heard it before...
|
||||
*/
|
||||
if (error || newp == NULL ||
|
||||
strcmp(cname, ptmp->p_limit->pl_corename) == 0)
|
||||
return (error);
|
||||
strcmp(cname, ptmp->p_limit->pl_corename) == 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* no error yet and cname now has the new core name in it.
|
||||
|
@ -652,19 +656,25 @@ sysctl_proc_corename(SYSCTLFN_ARGS)
|
|||
* or end in ".core" or "/core".
|
||||
*/
|
||||
len = strlen(cname);
|
||||
if (len < 4)
|
||||
return (EINVAL);
|
||||
if (strcmp(cname + len - 4, "core") != 0)
|
||||
return (EINVAL);
|
||||
if (len > 4 && cname[len - 5] != '/' && cname[len - 5] != '.')
|
||||
return (EINVAL);
|
||||
if (len < 4) {
|
||||
error = EINVAL;
|
||||
} else if (strcmp(cname + len - 4, "core") != 0) {
|
||||
error = EINVAL;
|
||||
} else if (len > 4 && cname[len - 5] != '/' && cname[len - 5] != '.') {
|
||||
error = EINVAL;
|
||||
}
|
||||
if (error != 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* hmm...looks good. now...where do we put it?
|
||||
*/
|
||||
tmp = malloc(len + 1, M_TEMP, M_WAITOK|M_CANFAIL);
|
||||
if (tmp == NULL)
|
||||
return (ENOMEM);
|
||||
if (tmp == NULL) {
|
||||
error = ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
strlcpy(tmp, cname, len + 1);
|
||||
|
||||
lim = ptmp->p_limit;
|
||||
|
@ -676,8 +686,9 @@ sysctl_proc_corename(SYSCTLFN_ARGS)
|
|||
if (lim->pl_corename != defcorename)
|
||||
free(lim->pl_corename, M_TEMP);
|
||||
lim->pl_corename = tmp;
|
||||
|
||||
return (error);
|
||||
done:
|
||||
PNBUF_PUT(cname);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_sig.c,v 1.214 2006/02/02 17:48:51 elad Exp $ */
|
||||
/* $NetBSD: kern_sig.c,v 1.215 2006/02/04 12:09:50 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1989, 1991, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.214 2006/02/02 17:48:51 elad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.215 2006/02/04 12:09:50 yamt Exp $");
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_compat_sunos.h"
|
||||
|
@ -2095,7 +2095,7 @@ coredump(struct lwp *l, const char *pattern)
|
|||
struct mount *mp;
|
||||
struct coredump_iostate io;
|
||||
int error, error1;
|
||||
char name[MAXPATHLEN];
|
||||
char *name = NULL;
|
||||
|
||||
p = l->l_proc;
|
||||
vm = p->p_vmspace;
|
||||
|
@ -2125,30 +2125,39 @@ restart:
|
|||
*/
|
||||
vp = p->p_cwdi->cwdi_cdir;
|
||||
if (vp->v_mount == NULL ||
|
||||
(vp->v_mount->mnt_flag & MNT_NOCOREDUMP) != 0)
|
||||
return (EPERM);
|
||||
(vp->v_mount->mnt_flag & MNT_NOCOREDUMP) != 0) {
|
||||
error = EPERM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (p->p_flag & P_SUGID && security_setidcore_dump)
|
||||
pattern = security_setidcore_path;
|
||||
|
||||
if (pattern == NULL)
|
||||
pattern = p->p_limit->pl_corename;
|
||||
if ((error = build_corename(p, name, pattern, sizeof(name))) != 0)
|
||||
return error;
|
||||
|
||||
if (name == NULL) {
|
||||
name = PNBUF_GET();
|
||||
}
|
||||
error = build_corename(p, name, pattern, MAXPATHLEN);
|
||||
if (error != 0) {
|
||||
goto done;
|
||||
}
|
||||
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, l);
|
||||
error = vn_open(&nd, O_CREAT | O_NOFOLLOW | FWRITE, S_IRUSR | S_IWUSR);
|
||||
if (error)
|
||||
return (error);
|
||||
if (error) {
|
||||
goto done;
|
||||
}
|
||||
vp = nd.ni_vp;
|
||||
|
||||
if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
|
||||
VOP_UNLOCK(vp, 0);
|
||||
if ((error = vn_close(vp, FWRITE, cred, l)) != 0)
|
||||
return (error);
|
||||
if ((error = vn_close(vp, FWRITE, cred, l)) != 0) {
|
||||
goto done;
|
||||
}
|
||||
if ((error = vn_start_write(NULL, &mp,
|
||||
V_WAIT | V_SLEEPONLY | V_PCATCH)) != 0)
|
||||
return (error);
|
||||
V_WAIT | V_SLEEPONLY | V_PCATCH)) != 0) {
|
||||
goto done;
|
||||
}
|
||||
goto restart;
|
||||
}
|
||||
|
||||
|
@ -2184,6 +2193,10 @@ restart:
|
|||
error1 = vn_close(vp, FWRITE, cred, l);
|
||||
if (error == 0)
|
||||
error = error1;
|
||||
done:
|
||||
if (name != NULL) {
|
||||
PNBUF_PUT(name);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_lookup.c,v 1.65 2005/12/27 17:24:07 chs Exp $ */
|
||||
/* $NetBSD: vfs_lookup.c,v 1.66 2006/02/04 12:09:50 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.65 2005/12/27 17:24:07 chs Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.66 2006/02/04 12:09:50 yamt Exp $");
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_systrace.h"
|
||||
|
@ -108,10 +108,11 @@ struct pool_cache pnbuf_cache; /* pathname buffer cache */
|
|||
static int
|
||||
symlink_magic(struct proc *p, char *cp, int *len)
|
||||
{
|
||||
char tmp[MAXPATHLEN];
|
||||
char *tmp;
|
||||
int change, i, newlen;
|
||||
int termchar = '/';
|
||||
|
||||
tmp = PNBUF_GET();
|
||||
for (change = i = newlen = 0; i < *len; ) {
|
||||
if (cp[i] != '@') {
|
||||
tmp[newlen++] = cp[i++];
|
||||
|
@ -161,11 +162,11 @@ symlink_magic(struct proc *p, char *cp, int *len)
|
|||
}
|
||||
}
|
||||
|
||||
if (! change)
|
||||
return (0);
|
||||
|
||||
memcpy(cp, tmp, newlen);
|
||||
*len = newlen;
|
||||
if (change) {
|
||||
memcpy(cp, tmp, newlen);
|
||||
*len = newlen;
|
||||
}
|
||||
PNBUF_PUT(tmp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_syscalls.c,v 1.235 2005/12/12 16:26:33 elad Exp $ */
|
||||
/* $NetBSD: vfs_syscalls.c,v 1.236 2006/02/04 12:09:50 yamt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.235 2005/12/12 16:26:33 elad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.236 2006/02/04 12:09:50 yamt Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
#include "opt_compat_43.h"
|
||||
|
@ -728,7 +728,7 @@ done:
|
|||
if (cwdi->cwdi_rdir != NULL) {
|
||||
size_t len;
|
||||
char *bp;
|
||||
char *path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
|
||||
char *path = PNBUF_GET();
|
||||
if (!path)
|
||||
return ENOMEM;
|
||||
|
||||
|
@ -737,7 +737,7 @@ done:
|
|||
error = getcwd_common(cwdi->cwdi_rdir, rootvnode, &bp, path,
|
||||
MAXPATHLEN / 2, 0, l);
|
||||
if (error) {
|
||||
free(path, M_TEMP);
|
||||
PNBUF_PUT(path);
|
||||
return error;
|
||||
}
|
||||
len = strlen(bp);
|
||||
|
@ -760,7 +760,7 @@ done:
|
|||
else
|
||||
error = EPERM;
|
||||
}
|
||||
free(path, M_TEMP);
|
||||
PNBUF_PUT(path);
|
||||
}
|
||||
sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
|
||||
return error;
|
||||
|
|
Loading…
Reference in New Issue