Merge "Cope with argv[0] being null in the dynamic linker."
diff --git a/linker/linker_logger.cpp b/linker/linker_logger.cpp
index 08728af..b2ea320 100644
--- a/linker/linker_logger.cpp
+++ b/linker/linker_logger.cpp
@@ -85,13 +85,20 @@
   }
 
   flags_ = 0;
-  // check flag applied to all processes first
+
+  // Check flag applied to all processes first.
   std::string value = property_get(kSystemLdDebugProperty);
   flags_ |= ParseProperty(value);
 
-  // get process basename
+  // Ignore processes started without argv (http://b/33276926).
+  if (g_argv[0] == nullptr) {
+    return;
+  }
+
+  // Get process basename.
   const char* process_name_start = basename(g_argv[0]);
-  // remove ':' and everything after it. This is naming convention for
+
+  // Remove ':' and everything after it. This is the naming convention for
   // services: https://developer.android.com/guide/components/services.html
   const char* process_name_end = strchr(process_name_start, ':');
 
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index ddf0df5..d90b01e 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -1364,3 +1364,11 @@
   ASSERT_EQ(-1, execvp("/system/bin/does-not-exist", eth.GetArgs()));
   ASSERT_EQ(ENOENT, errno);
 }
+
+TEST(UNISTD_TEST, exec_argv0_null) {
+  // http://b/33276926
+  char* args[] = {nullptr};
+  char* envs[] = {nullptr};
+  ASSERT_EXIT(execve("/system/bin/run-as", args, envs), testing::ExitedWithCode(1),
+              "<unknown>: usage: run-as");
+}