Module Name:    src
Committed By:   uebayasi
Date:           Fri Apr 11 11:49:38 UTC 2014

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

Log Message:
Clarify stack size calculation in copyargs().  Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.381 -r1.382 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.381 src/sys/kern/kern_exec.c:1.382
--- src/sys/kern/kern_exec.c:1.381	Fri Apr 11 11:32:14 2014
+++ src/sys/kern/kern_exec.c	Fri Apr 11 11:49:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.381 2014/04/11 11:32:14 uebayasi Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.382 2014/04/11 11:49:38 uebayasi 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.381 2014/04/11 11:32:14 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.382 2014/04/11 11:49:38 uebayasi Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1485,6 +1485,10 @@ execve1(struct lwp *l, const char *path,
 	return error;
 }
 
+/*
+ * Copy argv and env strings from kernel buffer (argp) to the new stack.
+ * Those strings are located just after auxinfo.
+ */
 int
 copyargs(struct lwp *l, struct exec_package *pack, struct ps_strings *arginfo,
     char **stackp, void *argp)
@@ -1499,14 +1503,24 @@ copyargs(struct lwp *l, struct exec_pack
 	nullp = NULL;
 	argc = arginfo->ps_nargvstr;
 	envc = arginfo->ps_nenvstr;
+
+	/* argc on stack is long */
+	CTASSERT(sizeof(*cpp) == sizeof(argc));
+
+	dp = (char *)(cpp +
+	    1 +				/* argc */
+	    argc +			/* *argv[] */
+	    1 +				/* \0 */
+	    envc +			/* *env[] */
+	    1 +				/* \0 */
+	    pack->ep_esch->es_arglen);	/* auxinfo */
+	sp = argp;
+
 	if ((error = copyout(&argc, cpp++, sizeof(argc))) != 0) {
 		COPYPRINTF("", cpp - 1, sizeof(argc));
 		return error;
 	}
 
-	dp = (char *)(cpp + argc + envc + 2 + pack->ep_esch->es_arglen);
-	sp = argp;
-
 	/* XXX don't copy them out, remap them! */
 	arginfo->ps_argvstr = cpp; /* remember location of argv for later */
 

Reply via email to