@@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
@@ -42,7 +43,7 @@
|
||||
|
||||
static
|
||||
int
|
||||
exec_common_fork(void)
|
||||
exec_common_fork(int *result)
|
||||
{
|
||||
int pid, rv, status, err;
|
||||
|
||||
@@ -56,7 +57,7 @@ exec_common_fork(void)
|
||||
err = errno;
|
||||
report_begin("forking for test");
|
||||
report_result(pid, err);
|
||||
report_aborted();
|
||||
report_aborted(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -70,10 +71,11 @@ exec_common_fork(void)
|
||||
err = errno;
|
||||
report_begin("waiting for test subprocess");
|
||||
report_result(rv, err);
|
||||
report_failure();
|
||||
report_failure(result);
|
||||
return -1;
|
||||
}
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == MAGIC_STATUS) {
|
||||
*result = SUCCESS;
|
||||
return 1;
|
||||
}
|
||||
/* Oops... */
|
||||
@@ -84,98 +86,134 @@ exec_common_fork(void)
|
||||
else {
|
||||
report_warnx("exit %d", WEXITSTATUS(status));
|
||||
}
|
||||
report_failure();
|
||||
report_failure(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
exec_badprog(const void *prog, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
int result;
|
||||
char *args[2];
|
||||
args[0] = (char *)"foo";
|
||||
args[1] = NULL;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
if (exec_common_fork(&result) != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
report_begin(desc);
|
||||
rv = execv(prog, args);
|
||||
report_check(rv, errno, EFAULT);
|
||||
exit(MAGIC_STATUS);
|
||||
result = report_check(rv, errno, EFAULT);
|
||||
int code = result ? result : MAGIC_STATUS;
|
||||
exit(code);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
exec_emptyprog(void)
|
||||
{
|
||||
int rv;
|
||||
int result;
|
||||
char *args[2];
|
||||
args[0] = (char *)"foo";
|
||||
args[1] = NULL;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
if (exec_common_fork(&result) != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
report_begin("exec the empty string");
|
||||
rv = execv("", args);
|
||||
report_check2(rv, errno, EINVAL, EISDIR);
|
||||
exit(MAGIC_STATUS);
|
||||
result = report_check2(rv, errno, EINVAL, EISDIR);
|
||||
int code = result ? result : MAGIC_STATUS;
|
||||
exit(code);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
exec_badargs(void *args, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
int result;
|
||||
if (exec_common_fork(&result) != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
report_begin(desc);
|
||||
rv = execv("/bin/true", args);
|
||||
report_check(rv, errno, EFAULT);
|
||||
exit(MAGIC_STATUS);
|
||||
result = report_check(rv, errno, EFAULT);
|
||||
int code = result ? result : MAGIC_STATUS;
|
||||
exit(code);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
int
|
||||
exec_onearg(void *ptr, const char *desc)
|
||||
{
|
||||
int rv;
|
||||
int result;
|
||||
|
||||
char *args[3];
|
||||
args[0] = (char *)"foo";
|
||||
args[1] = (char *)ptr;
|
||||
args[2] = NULL;
|
||||
|
||||
if (exec_common_fork() != 0) {
|
||||
return;
|
||||
if (exec_common_fork(&result) != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
report_begin(desc);
|
||||
rv = execv("/bin/true", args);
|
||||
report_check(rv, errno, EFAULT);
|
||||
exit(MAGIC_STATUS);
|
||||
result = report_check(rv, errno, EFAULT);
|
||||
int code = result ? result : MAGIC_STATUS;
|
||||
exit(code);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
test_execv(void)
|
||||
{
|
||||
exec_badprog(NULL, "exec with NULL program");
|
||||
exec_badprog(INVAL_PTR, "exec with invalid pointer program");
|
||||
exec_badprog(KERN_PTR, "exec with kernel pointer program");
|
||||
int ntests = 0, result = 0, lost_points = 0;
|
||||
ntests++;
|
||||
result = exec_badprog(NULL, "exec with NULL program");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
exec_emptyprog();
|
||||
ntests++;
|
||||
result = exec_badprog(INVAL_PTR, "exec with invalid pointer program");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
exec_badargs(NULL, "exec with NULL arglist");
|
||||
exec_badargs(INVAL_PTR, "exec with invalid pointer arglist");
|
||||
exec_badargs(KERN_PTR, "exec with kernel pointer arglist");
|
||||
ntests++;
|
||||
result = exec_badprog(KERN_PTR, "exec with kernel pointer program");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
exec_onearg(INVAL_PTR, "exec with invalid pointer arg");
|
||||
exec_onearg(KERN_PTR, "exec with kernel pointer arg");
|
||||
ntests++;
|
||||
result = exec_emptyprog();
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = exec_badargs(NULL, "exec with NULL arglist");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = exec_badargs(INVAL_PTR, "exec with invalid pointer arglist");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = exec_badargs(KERN_PTR, "exec with kernel pointer arglist");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
|
||||
ntests++;
|
||||
result = exec_onearg(INVAL_PTR, "exec with invalid pointer arg");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
ntests++;
|
||||
result = exec_onearg(KERN_PTR, "exec with kernel pointer arg");
|
||||
handle_result(result, &lost_points);
|
||||
|
||||
if(!lost_points)
|
||||
success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
|
||||
}
|
||||
|
Reference in New Issue
Block a user