exec-should-not-search-current-directory.cpp 386 B

1234567891011121314151617181920
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. int main()
  5. {
  6. int fd = open("hax", O_CREAT | O_RDWR, 0755);
  7. ftruncate(fd, 0);
  8. close(fd);
  9. int rc = execlp("hax", "hax", nullptr);
  10. int saved_errno = errno;
  11. unlink("hax");
  12. if (rc == -1 && saved_errno == ENOEXEC) {
  13. printf("FAIL\n");
  14. return 1;
  15. }
  16. printf("PASS\n");
  17. return 0;
  18. }