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