TestLibCExec.cpp 534 B

1234567891011121314151617181920212223242526
  1. /*
  2. * Copyright (c) 2018-2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <errno.h>
  8. #include <fcntl.h>
  9. #include <stdio.h>
  10. #include <unistd.h>
  11. TEST_CASE(exec_should_not_search_current_directory)
  12. {
  13. int fd = open("hax", O_CREAT | O_RDWR, 0755);
  14. ftruncate(fd, 0);
  15. close(fd);
  16. int rc = execlp("hax", "hax", nullptr);
  17. int saved_errno = errno;
  18. perror("execlp");
  19. unlink("hax");
  20. EXPECT_EQ(rc, -1);
  21. EXPECT_NE(saved_errno, ENOEXEC);
  22. }