OSDN Git Service

Fix execvp/execvpe behavior with absolute paths and ENOEXEC.
authorElliott Hughes <enh@google.com>
Fri, 26 Aug 2016 00:40:27 +0000 (17:40 -0700)
committerElliott Hughes <enh@google.com>
Fri, 26 Aug 2016 00:40:27 +0000 (17:40 -0700)
Bug: http://b/31091962
Change-Id: Id0b3d41868f5e3ed1ccf618bfefb46609367bc9a

libc/bionic/exec.cpp
tests/unistd_test.cpp

index 354f931..c43eb90 100644 (file)
@@ -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.
index 69d1906..6299469 100644 (file)
@@ -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);
+}