5 int main(int argc
, char **argv
)
9 // This tests the case where argv and envp are NULL, which is easy to
10 // get wrong because it's an unusual case. It is also bad and only
11 // "worked" by accident with the linux kernel.
13 char *const argv_exe
[] = {"true", NULL
};
14 char *const v_null
[] = { NULL
};
15 char *const v_minus_one
[] = { (char *const) -1, NULL
};
17 #if defined(VGO_solaris)
18 const char *exe
= "/bin/true";
19 #elif defined(VGO_darwin)
20 const char *exe
= "/usr/bin/true";
21 #elif defined(VGO_freebsd)
22 const char *exe
= "/usr/bin/true";
24 const char *exe
= "/bin/true";
27 /* Try some bad argv and envp arguments, make sure the executable
28 doesn't actually exists, so execve doesn't accidentally succeeds. */
29 if (execve("/%/", NULL
, NULL
) >= 0)
31 if (execve("/%/", (void *)-1, NULL
) >= 0)
33 if (execve("/%/", v_null
, NULL
) >= 0)
35 if (execve("/%/", v_null
, v_null
) >= 0)
37 if (execve("/%/", v_minus_one
, NULL
) >= 0)
39 if (execve("/%/", v_minus_one
, v_null
) >= 0)
41 if (execve("/%/", v_minus_one
, v_minus_one
) >= 0)
44 /* Finally a correct execve. */
45 if (execve(exe
, argv_exe
, NULL
) < 0)