kernel32: Limit the environment variable size to 32767 in GetEnvironmentVariable

Bruno Jesus 00cpxxx at gmail.com
Fri May 30 19:59:08 CDT 2014


Fix for bug 12371, according to Anastasius Focht analysis from comment
https://bugs.winehq.org/show_bug.cgi?id=12371#c8

MSDN documentation:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683188%28v=vs.85%29.aspx
-------------- next part --------------
diff --git a/dlls/kernel32/environ.c b/dlls/kernel32/environ.c
index b6b3124..0d3a09c 100644
--- a/dlls/kernel32/environ.c
+++ b/dlls/kernel32/environ.c
@@ -176,6 +176,9 @@ DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size )
         return 0;
     }
 
+    /* Limit the size according to documentation to avoid failing due
+     * to a memory allocation error. */
+    size = min(size, 32767);
     if (!(valueW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR))))
         return 0;
 


More information about the wine-patches mailing list