tests: add a basic test for argc == 0
The kernel should reject such exec()s now, early on. Instead of adding the needed boilerplate to write a test in C, just add an -n argument for "(n)ull argv" to the execve helper and exec this other helper that just exits silently with argv count. Reviewed by: emaste, kib, markj (all previous version) Differential Revision: https://reviews.freebsd.org/D34045
This commit is contained in:
parent
773fa8cd13
commit
e5b431fc0c
tests/sys/kern/execve
@ -10,6 +10,7 @@ ATF_TESTS_SH+= execve_test
|
||||
|
||||
PROGS+= good_aout
|
||||
PROGS+= execve_helper
|
||||
PROGS+= execve_argc_helper
|
||||
|
||||
LDFLAGS.goodaout+= -static
|
||||
|
||||
|
15
tests/sys/kern/execve/execve_argc_helper.c
Normal file
15
tests/sys/kern/execve/execve_argc_helper.c
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This file is in the public domain.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv __unused)
|
||||
{
|
||||
|
||||
printf("%d\n", argc);
|
||||
return (0);
|
||||
}
|
@ -38,17 +38,24 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Passing -n == null_argv */
|
||||
static char * const null_argv[] = { NULL };
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s <progname>\n", argv[0]);
|
||||
if (argc == 2) {
|
||||
execve(argv[1], &argv[1], NULL);
|
||||
} else if (argc == 3 && strcmp(argv[1], "-n") == 0) {
|
||||
execve(argv[2], null_argv, NULL);
|
||||
} else {
|
||||
fprintf(stderr, "usage: %s [-n] <progname>\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
execve(argv[1], &argv[1], NULL);
|
||||
err(1, "execve failed");
|
||||
}
|
||||
|
@ -99,6 +99,23 @@ trunc_aout_body()
|
||||
-x "cd $(atf_get_srcdir) && ./execve_helper trunc_aout"
|
||||
}
|
||||
|
||||
empty_args_head()
|
||||
{
|
||||
atf_set "descr" "Empty argv behavior"
|
||||
}
|
||||
empty_args_body()
|
||||
{
|
||||
atf_check -o inline:"1\n" \
|
||||
-x "cd $(atf_get_srcdir) && ./execve_helper execve_argc_helper"
|
||||
|
||||
# Historically we allowed argc == 0, while execve(2) claimed we didn't.
|
||||
# execve() should kick back an EINVAL now. We verified the helper was
|
||||
# there/working in the check just above.
|
||||
atf_check -s exit:1 \
|
||||
-e match:".+Invalid argument$" \
|
||||
-x "cd $(atf_get_srcdir) && ./execve_helper -n execve_argc_helper"
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case bad_interp_len
|
||||
@ -111,5 +128,6 @@ atf_init_test_cases()
|
||||
atf_add_test_case script_arg_nospace
|
||||
atf_add_test_case sparse_aout
|
||||
atf_add_test_case trunc_aout
|
||||
atf_add_test_case empty_args
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user