Module Name:    src
Committed By:   christos
Date:           Fri Oct 24 21:13:30 UTC 2014

Modified Files:
        src/sys/kern: kern_exec.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.408 -r1.409 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.408 src/sys/kern/kern_exec.c:1.409
--- src/sys/kern/kern_exec.c:1.408	Sun Jun 22 13:23:34 2014
+++ src/sys/kern/kern_exec.c	Fri Oct 24 17:13:30 2014
@@ -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"
@@ -1336,6 +1336,12 @@ execve1(struct lwp *l, const char *path,
 }
 
 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)
 {
 	struct exec_package	* const epp = &data->ed_pack;
@@ -1348,10 +1354,7 @@ calcargs(struct execve_data * restrict d
 	    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
 		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) {

Reply via email to