PR/49287: David Holland: Skip the right number of bytes to go over the first

argument in the argv vector. Fixes netbsd32 script execution, where you lost
the first argument because it skipped 8 bytes instead of 4.
This commit is contained in:
christos 2014-10-24 21:13:30 +00:00
parent 1a3570e51c
commit f9128b659c
1 changed files with 10 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.408 2014/06/22 17:23:34 maxv Exp $ */
/* $NetBSD: kern_exec.c,v 1.409 2014/10/24 21:13:30 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408 2014/06/22 17:23:34 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.409 2014/10/24 21:13:30 christos Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@ -1335,6 +1335,12 @@ execve1(struct lwp *l, const char *path, char * const *args,
return error;
}
static size_t
ptrsz(const struct exec_package *epp)
{
return (epp->ep_flags & EXEC_32) ? sizeof(int) : sizeof(char *);
}
static size_t
calcargs(struct execve_data * restrict data, const size_t argenvstrlen)
{
@ -1348,10 +1354,7 @@ calcargs(struct execve_data * restrict data, const size_t argenvstrlen)
1 + /* \0 */
epp->ep_esch->es_arglen; /* auxinfo */
const size_t ptrsz = (epp->ep_flags & EXEC_32) ?
sizeof(int) : sizeof(char *);
return (nargenvptrs * ptrsz) + argenvstrlen;
return (nargenvptrs * ptrsz(epp)) + argenvstrlen;
}
static size_t
@ -1506,7 +1509,7 @@ copyinargs(struct execve_data * restrict data, char * const *args,
return EINVAL;
}
if (epp->ep_flags & EXEC_SKIPARG)
args++;
args = (const void *)((const char *)args + ptrsz(epp));
i = 0;
error = copyinargstrs(data, args, fetch_element, &dp, &i, ktr_execarg);
if (error != 0) {