From 3c3e4fb297fa80aaa00b6eb2e66284eb760eebeb Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 22 Nov 2024 03:44:20 -0800 Subject: [PATCH] Do not forward legacy `cmd.exe` variables to the server This fixes startup failures such as: ``` ERROR: While parsing option --client_env==C:=C:\Users\wyv: Variable definitions must be in the form of a 'name=value' assignment ``` Fixes #24448 Closes #24451. PiperOrigin-RevId: 699115724 Change-Id: Id7a2445e82b24384e9ade0c92ddb343f00e9ab2b --- src/main/cpp/option_processor_windows.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/cpp/option_processor_windows.cc b/src/main/cpp/option_processor_windows.cc index ce5b037cf26c0d..53bf1cff2f36a6 100644 --- a/src/main/cpp/option_processor_windows.cc +++ b/src/main/cpp/option_processor_windows.cc @@ -63,7 +63,14 @@ static void PreprocessEnvString(std::string* env_str) { #endif // defined(__CYGWIN__) static bool IsValidEnvName(std::string_view s) { - std::string_view name = s.substr(0, s.find('=')); + std::size_t first_equal = s.find('='); + if (first_equal == 0) { + // Skip over legacy environment variables that start with '=', e.g. '=C:' + // These are set by cmd.exe and can't be parsed by the Bazel server if + // passed into --client_env. + return false; + } + std::string_view name = s.substr(0, first_equal); return std::all_of(name.begin(), name.end(), [](char c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '(' || c == ')';