exec-null.c 512 B

123456789101112131415161718
  1. /* make sure we handle argv[0] == NULL */
  2. #include <unistd.h>
  3. int main(int argc, char *argv[])
  4. {
  5. /* since Linux https://github.com/torvalds/linux/commit/dcd46d897adb70d63e025f175a00a89797d31a43
  6. * kernel forces an empty first arg if execve is called
  7. * with argv == NULL.
  8. * so we need to handle argc == 1 for newer kernel as well
  9. */
  10. if (argc == 0 || argc == 1)
  11. return 0;
  12. char *exec_argv[1], *exec_envp[1];
  13. exec_argv[0] = exec_envp[0] = NULL;
  14. return execve("./exec-null", exec_argv, exec_envp);
  15. }