Fix for a bug in GetCORSystemDirectoryInternaL
authorEugene Rozenfeld <erozen@microsoft.com>
Thu, 10 Mar 2016 21:05:23 +0000 (13:05 -0800)
committerEugene Rozenfeld <erozen@microsoft.com>
Thu, 10 Mar 2016 21:05:23 +0000 (13:05 -0800)
Change 7045ca7a6de381b382a709dc0a61f49ca713d160 introduced a bug in
GetCORSystemDirectoryInternaL. The second parameter of GetRuntimeDirectory
is in/out so passing a pointer to an uninitialized cchBuffer was wrong.
The fix is to initialize cchBuffer to MAX_PATH - 1.

This was causing failures in some non CoreClr ngen scenarios.

src/dlls/mscoree/mscoree.cpp

index d42733a..74d3f97 100644 (file)
@@ -941,13 +941,13 @@ STDAPI GetCORSystemDirectoryInternaL(SString& pBuffer)
     return hr;
 
 #else // FEATURE_CORECLR || CROSSGEN_COMPILE
-    DWORD cchBuffer;
+    DWORD cchBuffer = MAX_PATH - 1;
     // Simply forward the call to the ICLRRuntimeInfo implementation.
     STATIC_CONTRACT_WRAPPER;
     HRESULT hr = S_OK;
     if (g_pCLRRuntime)
     {
-        WCHAR* temp = pBuffer.OpenUnicodeBuffer(MAX_PATH - 1);
+        WCHAR* temp = pBuffer.OpenUnicodeBuffer(cchBuffer);
         hr = g_pCLRRuntime->GetRuntimeDirectory(temp, &cchBuffer);
         pBuffer.CloseBuffer(cchBuffer - 1);
     }