From: Elliott Hughes Date: Fri, 26 Aug 2016 00:40:27 +0000 (-0700) Subject: Fix execvp/execvpe behavior with absolute paths and ENOEXEC. X-Git-Tag: android-x86-8.1-r1~224^2^2~85^2~129^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=63615066d9f0b0b1c653c91a9b305e6c292c835a;p=android-x86%2Fbionic.git Fix execvp/execvpe behavior with absolute paths and ENOEXEC. Bug: http://b/31091962 Change-Id: Id0b3d41868f5e3ed1ccf618bfefb46609367bc9a --- diff --git a/libc/bionic/exec.cpp b/libc/bionic/exec.cpp index 354f931ba..c43eb9065 100644 --- a/libc/bionic/exec.cpp +++ b/libc/bionic/exec.cpp @@ -115,7 +115,8 @@ int execvpe(const char* name, char* const* argv, char* const* envp) { // If it's an absolute or relative path name, it's easy. if (strchr(name, '/') && execve(name, argv, envp) == -1) { - return __exec_as_script(name, argv, envp); + if (errno == ENOEXEC) return __exec_as_script(name, argv, envp); + return -1; } // Get the path we're searching. diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 69d19063a..629946912 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -1272,3 +1272,12 @@ TEST(UNISTD_TEST, execvpe_ENOEXEC) { // implementation. eth.Run([&]() { execvpe(tf.filename, eth.GetArgs(), eth.GetEnv()); }, 0, "script\n"); } + +TEST(UNISTD_TEST, execvp_libcore_test_55017) { + ExecTestHelper eth; + eth.SetArgs({"/system/bin/does-not-exist", nullptr}); + + errno = 0; + ASSERT_EQ(-1, execvp("/system/bin/does-not-exist", eth.GetArgs())); + ASSERT_EQ(ENOENT, errno); +}