blob: 97ee3bf1f71fdc98f2c4c58b8b17791d7ff38e6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <sys/wait.h>
#include "common.h"
/*
* Test for dynamic executables with no read permissions. This test relies on
* being linked dynamically.
*/
int
main(int argc, char ** argv)
{
char *executable, cp_cmd[PATH_MAX + 9];
int status;
if (strcmp(argv[0], "DO CHECK") == 0)
exit(EXIT_SUCCESS);
start(86);
/* Make a copy of this binary which is executable-only. */
executable = argv[0];
snprintf(cp_cmd, sizeof(cp_cmd), "cp ../%s .", executable);
status = system(cp_cmd);
if (status < 0 || !WIFEXITED(status) ||
WEXITSTATUS(status) != EXIT_SUCCESS) e(0);
if (chmod(executable, S_IXUSR) != 0) e(0);
/* Invoke the changed binary in a child process. */
switch (fork()) {
case -1:
e(0);
case 0:
execl(executable, "DO CHECK", NULL);
exit(EXIT_FAILURE);
default:
if (wait(&status) <= 0) e(0);
if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
e(0);
}
quit();
/* NOTREACHED */
}
|