do_fork: Propagate error code returned by mcexec
Refs: #731 Change-Id: I7eb52c1c76103d65d108b18b7beaf8041b51cd03
This commit is contained in:
committed by
Dominique Martinet
parent
0758f6254e
commit
1cbe389879
55
test/issues/731/g310a.c
Normal file
55
test/issues/731/g310a.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* g310a: If superuser try to fork() after seteuid(bin), ...
|
||||
*/
|
||||
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int error;
|
||||
struct passwd *pwd;
|
||||
pid_t pid;
|
||||
int ws;
|
||||
|
||||
if (geteuid()) {
|
||||
printf("not a superuser\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
pwd = getpwnam("bin");
|
||||
if (!pwd) {
|
||||
perror("getpwnam");
|
||||
return 1;
|
||||
}
|
||||
|
||||
error = seteuid(pwd->pw_uid);
|
||||
if (error) {
|
||||
perror("seteuid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("fork");
|
||||
}
|
||||
|
||||
if (!pid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid = waitpid(pid, &ws, 0);
|
||||
if (pid == -1) {
|
||||
perror("waitpid");
|
||||
return 1;
|
||||
}
|
||||
if (ws) {
|
||||
printf("ws: %#x\n", ws);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("done.\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user