Module Name:    src
Committed By:   christos
Date:           Tue Sep 17 15:19:28 UTC 2019

Modified Files:
        src/sys/compat/netbsd32: netbsd32_execve.c
        src/sys/compat/sunos32: sunos32_misc.c
        src/sys/kern: kern_exec.c
        src/sys/sys: exec.h

Log Message:
Add a boolean argument to indicate if we have a path/true (execve) or an
fd/false (fexecve). This is needed to differentiate between them because
NULL/-1 can be readily passed from userland.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/compat/netbsd32/netbsd32_execve.c
cvs rdiff -u -r1.80 -r1.81 src/sys/compat/sunos32/sunos32_misc.c
cvs rdiff -u -r1.480 -r1.481 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.155 -r1.156 src/sys/sys/exec.h

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

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_execve.c
diff -u src/sys/compat/netbsd32/netbsd32_execve.c:1.40 src/sys/compat/netbsd32/netbsd32_execve.c:1.41
--- src/sys/compat/netbsd32/netbsd32_execve.c:1.40	Sun Sep 15 16:26:51 2019
+++ src/sys/compat/netbsd32/netbsd32_execve.c	Tue Sep 17 11:19:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_execve.c,v 1.40 2019/09/15 20:26:51 christos Exp $	*/
+/*	$NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.40 2019/09/15 20:26:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,7 +72,7 @@ netbsd32_execve(struct lwp *l, const str
 		syscallarg(netbsd32_charpp) envp;
 	} */
 
-	return execve1(l, SCARG_P32(uap, path), -1, SCARG_P32(uap, argp),
+	return execve1(l, true, SCARG_P32(uap, path), -1, SCARG_P32(uap, argp),
 	    SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
 }
 
@@ -86,7 +86,7 @@ netbsd32_fexecve(struct lwp *l, const st
 		syscallarg(netbsd32_charpp) envp;
 	} */
 
-	return execve1(l, NULL, SCARG(uap, fd), SCARG_P32(uap, argp),
+	return execve1(l, false, NULL, SCARG(uap, fd), SCARG_P32(uap, argp),
 	    SCARG_P32(uap, envp), netbsd32_execve_fetch_element);
 }
 

Index: src/sys/compat/sunos32/sunos32_misc.c
diff -u src/sys/compat/sunos32/sunos32_misc.c:1.80 src/sys/compat/sunos32/sunos32_misc.c:1.81
--- src/sys/compat/sunos32/sunos32_misc.c:1.80	Tue Sep 17 03:58:54 2019
+++ src/sys/compat/sunos32/sunos32_misc.c	Tue Sep 17 11:19:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sunos32_misc.c,v 1.80 2019/09/17 07:58:54 mrg Exp $	*/
+/*	$NetBSD: sunos32_misc.c,v 1.81 2019/09/17 15:19:27 christos Exp $	*/
 /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp	*/
 
 /*
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.80 2019/09/17 07:58:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.81 2019/09/17 15:19:27 christos Exp $");
 
 #define COMPAT_SUNOS 1
 
@@ -388,7 +388,7 @@ sunos32_sys_execv(struct lwp *l, const s
 	} */
 	const char *path = SCARG_P32(uap, path);
 
-	return execve1(l, path, -1, SCARG_P32(uap, argp), NULL,
+	return execve1(l, true, path, -1, SCARG_P32(uap, argp), NULL,
 	    sunos32_execve_fetch_element);
 }
 
@@ -402,9 +402,8 @@ sunos32_sys_execve(struct lwp *l, const 
 	} */
 	const char *path = SCARG_P32(uap, path);
 
-	return execve1(l, path, -1, SCARG_P32(uap, argp),
-	    SCARG_P32(uap, envp),
-	    sunos32_execve_fetch_element);
+	return execve1(l, true, path, -1, SCARG_P32(uap, argp),
+	    SCARG_P32(uap, envp), sunos32_execve_fetch_element);
 }
 
 int

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.480 src/sys/kern/kern_exec.c:1.481
--- src/sys/kern/kern_exec.c:1.480	Sun Sep 15 16:23:50 2019
+++ src/sys/kern/kern_exec.c	Tue Sep 17 11:19:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.480 2019/09/15 20:23:50 christos Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.481 2019/09/17 15:19:27 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.480 2019/09/15 20:23:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.481 2019/09/17 15:19:27 christos Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -583,7 +583,7 @@ sys_execve(struct lwp *l, const struct s
 		syscallarg(char * const *)	envp;
 	} */
 
-	return execve1(l, SCARG(uap, path), -1, SCARG(uap, argp),
+	return execve1(l, true, SCARG(uap, path), -1, SCARG(uap, argp),
 	    SCARG(uap, envp), execve_fetch_element);
 }
 
@@ -597,7 +597,7 @@ sys_fexecve(struct lwp *l, const struct 
 		syscallarg(char * const *)	envp;
 	} */
 
-	return execve1(l, NULL, SCARG(uap, fd), SCARG(uap, argp),
+	return execve1(l, false, NULL, SCARG(uap, fd), SCARG(uap, argp),
 	    SCARG(uap, envp), execve_fetch_element);
 }
 
@@ -719,8 +719,9 @@ exec_vm_minaddr(vaddr_t va_min)
 }
 
 static int
-execve_loadvm(struct lwp *l, const char *path, int fd, char * const *args,
-	char * const *envs, execve_fetch_element_t fetch_element,
+execve_loadvm(struct lwp *l, bool has_path, const char *path, int fd,
+	char * const *args, char * const *envs,
+	execve_fetch_element_t fetch_element,
 	struct execve_data * restrict data)
 {
 	struct exec_package	* const epp = &data->ed_pack;
@@ -770,14 +771,7 @@ execve_loadvm(struct lwp *l, const char 
 	 */
 	rw_enter(&p->p_reflock, RW_WRITER);
 
-	if (path == NULL) {
-		data->ed_pathbuf = pathbuf_assimilate(strcpy(PNBUF_GET(), "/"));
-		data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
-		epp->ep_kname = "*fexecve*";
-		data->ed_resolvedname = NULL;
-		epp->ep_resolvedname = NULL;
-		epp->ep_xfd = fd;
-	} else {
+	if (has_path) {
 		size_t	offs;
 		/*
 		 * Init the namei data to point the file user's program name.
@@ -794,6 +788,13 @@ execve_loadvm(struct lwp *l, const char 
 		data->ed_resolvedname = PNBUF_GET();
 		epp->ep_resolvedname = data->ed_resolvedname;
 		epp->ep_xfd = -1;
+	} else {
+		data->ed_pathbuf = pathbuf_assimilate(strcpy(PNBUF_GET(), "/"));
+		data->ed_pathstring = pathbuf_stringcopy_get(data->ed_pathbuf);
+		epp->ep_kname = "*fexecve*";
+		data->ed_resolvedname = NULL;
+		epp->ep_resolvedname = NULL;
+		epp->ep_xfd = fd;
 	}
 
 
@@ -1406,13 +1407,15 @@ execve_runproc(struct lwp *l, struct exe
 }
 
 int
-execve1(struct lwp *l, const char *path, int fd, char * const *args,
-    char * const *envs, execve_fetch_element_t fetch_element)
+execve1(struct lwp *l, bool has_path, const char *path, int fd,
+    char * const *args, char * const *envs,
+    execve_fetch_element_t fetch_element)
 {
 	struct execve_data data;
 	int error;
 
-	error = execve_loadvm(l, path, fd, args, envs, fetch_element, &data);
+	error = execve_loadvm(l, has_path, path, fd, args, envs, fetch_element,
+	    &data);
 	if (error)
 		return error;
 	error = execve_runproc(l, &data, false, false);
@@ -2436,7 +2439,7 @@ do_posix_spawn(struct lwp *l1, pid_t *pi
 	 * Do the first part of the exec now, collect state
 	 * in spawn_data.
 	 */
-	error = execve_loadvm(l1, path, -1, argv,
+	error = execve_loadvm(l1, true, path, -1, argv,
 	    envp, fetch, &spawn_data->sed_exec);
 	if (error == EJUSTRETURN)
 		error = 0;

Index: src/sys/sys/exec.h
diff -u src/sys/sys/exec.h:1.155 src/sys/sys/exec.h:1.156
--- src/sys/sys/exec.h:1.155	Sun Sep 15 16:26:27 2019
+++ src/sys/sys/exec.h	Tue Sep 17 11:19:27 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec.h,v 1.155 2019/09/15 20:26:27 christos Exp $	*/
+/*	$NetBSD: exec.h,v 1.156 2019/09/17 15:19:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -302,14 +302,14 @@ void	new_vmcmd(struct exec_vmcmd_set *,
 	new_vmcmd(evsp,lwp,len,addr,vp,offset,prot,flags)
 
 typedef	int (*execve_fetch_element_t)(char * const *, size_t, char **);
-int	execve1(struct lwp *, const char *, int, char * const *, char * const *,
-    execve_fetch_element_t);
+int	execve1(struct lwp *, bool, const char *, int, char * const *,
+    char * const *, execve_fetch_element_t);
 
 struct posix_spawn_file_actions;
 struct posix_spawnattr;
 int	check_posix_spawn	(struct lwp *);
 void	posix_spawn_fa_free(struct posix_spawn_file_actions *, size_t);
-int	do_posix_spawn(struct lwp *, pid_t *, bool*, const char *,
+int	do_posix_spawn(struct lwp *, pid_t *, bool *, const char *,
     struct posix_spawn_file_actions *, struct posix_spawnattr *,
     char *const *, char *const *, execve_fetch_element_t);
 int      exec_makepathbuf(struct lwp *, const char *, enum uio_seg,

Reply via email to