summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c16
-rw-r--r--sys/kern/imgact_shell.c3
-rw-r--r--sys/kern/kern_exec.c36
-rw-r--r--sys/sys/imgact.h1
-rw-r--r--sys/vm/vm_init.c4
5 files changed, 33 insertions, 27 deletions
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 1144f80..3dfed77 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -86,7 +86,6 @@ __FBSDID("$FreeBSD$");
#endif
#include <vm/vm.h>
-#include <vm/vm_kern.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_map.h>
@@ -279,19 +278,18 @@ freebsd32_exec_copyin_args(struct image_args *args, char *fname,
return (EFAULT);
/*
- * Allocate temporary demand zeroed space for argument and
- * environment strings
+ * Allocate demand-paged memory for the file name, argument, and
+ * environment strings.
*/
- args->buf = (char *) kmem_alloc_wait(exec_map,
- PATH_MAX + ARG_MAX + MAXSHELLCMDLEN);
- if (args->buf == NULL)
- return (ENOMEM);
+ error = exec_alloc_args(args);
+ if (error != 0)
+ return (error);
/*
* Copy the file name.
*/
if (fname != NULL) {
- args->fname = args->buf + MAXSHELLCMDLEN;
+ args->fname = args->buf;
error = (segflg == UIO_SYSSPACE) ?
copystr(fname, args->fname, PATH_MAX, &length) :
copyinstr(fname, args->fname, PATH_MAX, &length);
@@ -300,7 +298,7 @@ freebsd32_exec_copyin_args(struct image_args *args, char *fname,
} else
length = 0;
- args->begin_argv = args->buf + MAXSHELLCMDLEN + length;
+ args->begin_argv = args->buf + length;
args->endp = args->begin_argv;
args->stringspace = ARG_MAX;
diff --git a/sys/kern/imgact_shell.c b/sys/kern/imgact_shell.c
index 5eb3065..d0ef87c 100644
--- a/sys/kern/imgact_shell.c
+++ b/sys/kern/imgact_shell.c
@@ -240,8 +240,7 @@ exec_shell_imgact(imgp)
imgp->args->stringspace, NULL);
if (error == 0)
- error = copystr(imgp->args->begin_argv, imgp->interpreter_name,
- MAXSHELLCMDLEN, NULL);
+ imgp->interpreter_name = imgp->args->begin_argv;
if (sname != NULL)
sbuf_delete(sname);
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 1f0944c..2242328 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -375,7 +375,7 @@ do_execve(td, args, mac_p)
imgp->vmspace_destroyed = 0;
imgp->interpreted = 0;
imgp->opened = 0;
- imgp->interpreter_name = args->buf;
+ imgp->interpreter_name = NULL;
imgp->auxargs = NULL;
imgp->vp = NULL;
imgp->object = NULL;
@@ -1078,23 +1078,20 @@ exec_copyin_args(struct image_args *args, char *fname,
bzero(args, sizeof(*args));
if (argv == NULL)
return (EFAULT);
+
/*
- * Allocate temporary demand zeroed space for argument and
- * environment strings:
- *
- * o ARG_MAX for argument and environment;
- * o MAXSHELLCMDLEN for the name of interpreters.
+ * Allocate demand-paged memory for the file name, argument, and
+ * environment strings.
*/
- args->buf = (char *) kmem_alloc_wait(exec_map,
- PATH_MAX + ARG_MAX + MAXSHELLCMDLEN);
- if (args->buf == NULL)
- return (ENOMEM);
+ error = exec_alloc_args(args);
+ if (error != 0)
+ return (error);
/*
* Copy the file name.
*/
if (fname != NULL) {
- args->fname = args->buf + MAXSHELLCMDLEN;
+ args->fname = args->buf;
error = (segflg == UIO_SYSSPACE) ?
copystr(fname, args->fname, PATH_MAX, &length) :
copyinstr(fname, args->fname, PATH_MAX, &length);
@@ -1103,7 +1100,7 @@ exec_copyin_args(struct image_args *args, char *fname,
} else
length = 0;
- args->begin_argv = args->buf + MAXSHELLCMDLEN + length;
+ args->begin_argv = args->buf + length;
args->endp = args->begin_argv;
args->stringspace = ARG_MAX;
@@ -1156,13 +1153,26 @@ err_exit:
return (error);
}
+/*
+ * Allocate temporary demand-paged, zero-filled memory for the file name,
+ * argument, and environment strings. Returns zero if the allocation succeeds
+ * and ENOMEM otherwise.
+ */
+int
+exec_alloc_args(struct image_args *args)
+{
+
+ args->buf = (char *)kmem_alloc_wait(exec_map, PATH_MAX + ARG_MAX);
+ return (args->buf != NULL ? 0 : ENOMEM);
+}
+
void
exec_free_args(struct image_args *args)
{
if (args->buf != NULL) {
kmem_free_wakeup(exec_map, (vm_offset_t)args->buf,
- PATH_MAX + ARG_MAX + MAXSHELLCMDLEN);
+ PATH_MAX + ARG_MAX);
args->buf = NULL;
}
}
diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h
index d20c491..c4075fa 100644
--- a/sys/sys/imgact.h
+++ b/sys/sys/imgact.h
@@ -78,6 +78,7 @@ struct thread;
#define IMGACT_CORE_COMPRESS 0x01
+int exec_alloc_args(struct image_args *);
int exec_check_permissions(struct image_params *);
register_t *exec_copyout_strings(struct image_params *);
void exec_free_args(struct image_args *);
diff --git a/sys/vm/vm_init.c b/sys/vm/vm_init.c
index 8775937..c507691 100644
--- a/sys/vm/vm_init.c
+++ b/sys/vm/vm_init.c
@@ -73,7 +73,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/selinfo.h>
-#include <sys/imgact.h>
#include <sys/pipe.h>
#include <sys/bio.h>
#include <sys/buf.h>
@@ -195,8 +194,7 @@ again:
(long)nswbuf * MAXPHYS, FALSE);
pager_map->system_map = 1;
exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr,
- exec_map_entries * round_page(PATH_MAX + ARG_MAX + MAXSHELLCMDLEN),
- FALSE);
+ exec_map_entries * round_page(PATH_MAX + ARG_MAX), FALSE);
pipe_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, maxpipekva,
FALSE);
OpenPOWER on IntegriCloud