aboutsummaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorBrooks Davis <brooks@FreeBSD.org>2018-11-29 21:00:56 +0000
committerBrooks Davis <brooks@FreeBSD.org>2018-11-29 21:00:56 +0000
commitf373437a01a361a76e3ba53e057d025e6536d0fd (patch)
tree48d4d749d3e70f2736330d671e4b721ff5c3debd /sys/compat
parentdead7b5e47d14f6560c5be40e673664ba20c670f (diff)
downloadsrc-f373437a01a361a76e3ba53e057d025e6536d0fd.tar.gz
src-f373437a01a361a76e3ba53e057d025e6536d0fd.zip
Add helper functions to copy strings into struct image_args.
Given a zeroed struct image_args with an allocated buf member, exec_args_add_fname() must be called to install a file name (or NULL). Then zero or more calls to exec_args_add_env() followed by zero or more calls to exec_args_add_env(). exec_args_adjust_args() may be called after args and/or env to allow an interpreter to be prepended to the argument list. To allow code reuse when adding arg and env variables, begin_envv should be accessed with the accessor exec_args_get_begin_envv() which handles the case when no environment entries have been added. Use these functions to simplify exec_copyin_args() and freebsd32_exec_copyin_args(). Reviewed by: kib Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D15468
Notes
Notes: svn path=/head/; revision=341263
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/cloudabi32/cloudabi32_module.c5
-rw-r--r--sys/compat/cloudabi64/cloudabi64_module.c5
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c40
3 files changed, 13 insertions, 37 deletions
diff --git a/sys/compat/cloudabi32/cloudabi32_module.c b/sys/compat/cloudabi32/cloudabi32_module.c
index 001c673a7d7a..51beae7519ac 100644
--- a/sys/compat/cloudabi32/cloudabi32_module.c
+++ b/sys/compat/cloudabi32/cloudabi32_module.c
@@ -54,7 +54,7 @@ cloudabi32_copyout_strings(struct image_params *imgp)
/* Copy out program arguments. */
args = imgp->args;
- len = args->begin_envv - args->begin_argv;
+ len = exec_args_get_begin_envv(args) - args->begin_argv;
begin = rounddown2(imgp->sysent->sv_usrstack - len, sizeof(register_t));
copyout(args->begin_argv, (void *)begin, len);
return ((register_t *)begin);
@@ -109,7 +109,8 @@ cloudabi32_fixup(register_t **stack_base, struct image_params *imgp)
* exec_copyin_data_fds(). Undo this by reducing the length.
*/
args = (Elf32_Auxargs *)imgp->auxargs;
- argdatalen = imgp->args->begin_envv - imgp->args->begin_argv;
+ argdatalen = exec_args_get_begin_envv(imgp->args) -
+ imgp->args->begin_argv;
if (argdatalen > 0)
--argdatalen;
diff --git a/sys/compat/cloudabi64/cloudabi64_module.c b/sys/compat/cloudabi64/cloudabi64_module.c
index 9c71b87b08f4..fd0be086aac3 100644
--- a/sys/compat/cloudabi64/cloudabi64_module.c
+++ b/sys/compat/cloudabi64/cloudabi64_module.c
@@ -54,7 +54,7 @@ cloudabi64_copyout_strings(struct image_params *imgp)
/* Copy out program arguments. */
args = imgp->args;
- len = args->begin_envv - args->begin_argv;
+ len = exec_args_get_begin_envv(args) - args->begin_argv;
begin = rounddown2(imgp->sysent->sv_usrstack - len, sizeof(register_t));
copyout(args->begin_argv, (void *)begin, len);
return ((register_t *)begin);
@@ -109,7 +109,8 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
* exec_copyin_data_fds(). Undo this by reducing the length.
*/
args = (Elf64_Auxargs *)imgp->auxargs;
- argdatalen = imgp->args->begin_envv - imgp->args->begin_argv;
+ argdatalen = exec_args_get_begin_envv(imgp->args) -
+ imgp->args->begin_argv;
if (argdatalen > 0)
--argdatalen;
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 3c2cdec819b0..d596eb4d6acf 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -337,7 +337,6 @@ freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
{
char *argp, *envp;
u_int32_t *p32, arg;
- size_t length;
int error;
bzero(args, sizeof(*args));
@@ -355,19 +354,9 @@ freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
/*
* Copy the file name.
*/
- if (fname != NULL) {
- args->fname = args->buf;
- error = (segflg == UIO_SYSSPACE) ?
- copystr(fname, args->fname, PATH_MAX, &length) :
- copyinstr(fname, args->fname, PATH_MAX, &length);
- if (error != 0)
- goto err_exit;
- } else
- length = 0;
-
- args->begin_argv = args->buf + length;
- args->endp = args->begin_argv;
- args->stringspace = ARG_MAX;
+ error = exec_args_add_fname(args, fname, segflg);
+ if (error != 0)
+ goto err_exit;
/*
* extract arguments first
@@ -380,19 +369,11 @@ freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
if (arg == 0)
break;
argp = PTRIN(arg);
- error = copyinstr(argp, args->endp, args->stringspace, &length);
- if (error) {
- if (error == ENAMETOOLONG)
- error = E2BIG;
+ error = exec_args_add_arg(args, argp, UIO_USERSPACE);
+ if (error != 0)
goto err_exit;
- }
- args->stringspace -= length;
- args->endp += length;
- args->argc++;
}
- args->begin_envv = args->endp;
-
/*
* extract environment strings
*/
@@ -405,16 +386,9 @@ freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
if (arg == 0)
break;
envp = PTRIN(arg);
- error = copyinstr(envp, args->endp, args->stringspace,
- &length);
- if (error) {
- if (error == ENAMETOOLONG)
- error = E2BIG;
+ error = exec_args_add_env(args, envp, UIO_USERSPACE);
+ if (error != 0)
goto err_exit;
- }
- args->stringspace -= length;
- args->endp += length;
- args->envc++;
}
}