Merge pull request #23537 from janvorli/remove-gc-cpu-group-knowledge
[platform/upstream/coreclr.git] / src / vm / gcenv.ee.cpp
index 5c3b157..ffe3cc1 100644 (file)
@@ -1028,10 +1028,9 @@ MethodTable* GCToEEInterface::GetFreeObjectMethodTable()
     return g_pFreeObjectMethodTable;
 }
 
-// These are arbitrary, we shouldn't ever be having confrig keys or values
+// This is arbitrary, we shouldn't ever be having config keys
 // longer than these lengths.
 const size_t MaxConfigKeyLength = 255;
-const size_t MaxConfigValueLength = 255;
 
 bool GCToEEInterface::GetBooleanConfigValue(const char* key, bool* value)
 {
@@ -1164,8 +1163,17 @@ bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
         return false;
     }
 
+    int charCount = WideCharToMultiByte(CP_ACP, 0, out, -1 /* out is null-terminated */, NULL, 0, nullptr, nullptr);
+    if (charCount == 0)
+    {
+        // this should only happen if the config subsystem gives us a string that's not valid
+        // unicode.
+        CLRConfig::FreeConfigString(out);
+        return false;
+    }
+
     // not allocated on the stack since it escapes this function
-    AStringHolder configResult = new (nothrow) char[MaxConfigValueLength];
+    AStringHolder configResult = new (nothrow) char[charCount];
     if (!configResult)
     {
         CLRConfig::FreeConfigString(out);
@@ -1173,10 +1181,11 @@ bool GCToEEInterface::GetStringConfigValue(const char* key, const char** value)
     }
 
     if (WideCharToMultiByte(CP_ACP, 0, out, -1 /* out is null-terminated */,
-          configResult.GetValue(), MaxConfigKeyLength, nullptr, nullptr) == 0)
+          configResult.GetValue(), charCount, nullptr, nullptr) == 0)
     {
-        // this should only happen if the config subsystem gives us a string that's not valid
-        // unicode.
+        // this should never happen, the previous call to WideCharToMultiByte that computed the charCount should 
+        // have caught all issues.
+        assert(false);
         CLRConfig::FreeConfigString(out);
         return false;
     }