adb: handle some edge cases with process environments.

Change-Id: I0c20e58e14ef756a8c45dd5ea85f7301157a3c8e
diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp
index 0f89378..366ed07 100644
--- a/adb/shell_service.cpp
+++ b/adb/shell_service.cpp
@@ -250,13 +250,18 @@
     // Construct the environment for the child before we fork.
     passwd* pw = getpwuid(getuid());
     std::unordered_map<std::string, std::string> env;
+    if (environ) {
+        char** current = environ;
+        while (char* env_cstr = *current++) {
+            std::string env_string = env_cstr;
+            char* delimiter = strchr(env_string.c_str(), '=');
 
-    char** current = environ;
-    while (char* env_cstr = *current++) {
-        std::string env_string = env_cstr;
-        char* delimiter = strchr(env_string.c_str(), '=');
-        *delimiter++ = '\0';
-        env[env_string.c_str()] = delimiter;
+            // Drop any values that don't contain '='.
+            if (delimiter) {
+                *delimiter++ = '\0';
+                env[env_string.c_str()] = delimiter;
+            }
+        }
     }
 
     if (pw != nullptr) {