From 1c7ad37cf640f3c53a97a1a51a84d0270039d76f Mon Sep 17 00:00:00 2001
From: tatyana <tatyana@etersoft.ru>
Date: Tue, 11 Jun 2013 17:41:16 +0400
Subject: [PATCH 2/2] kernel32: Check the size of the string in CompareStringA.

---
 dlls/kernel32/locale.c       | 6 +++---
 dlls/kernel32/tests/locale.c | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index 86720ff..9ddf078 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -2979,7 +2979,7 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
     WCHAR *buf1W = NtCurrentTeb()->StaticUnicodeBuffer;
     WCHAR *buf2W = buf1W + 130;
     LPWSTR str1W, str2W;
-    INT len1W, len2W, ret;
+    INT len1W = 0, len2W = 0, ret;
     UINT locale_cp = CP_ACP;
 
     if (!str1 || !str2)
@@ -2994,7 +2994,7 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
 
     if (len1)
     {
-        len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
+        if (len1 <= 130) len1W = MultiByteToWideChar(locale_cp, 0, str1, len1, buf1W, 130);
         if (len1W)
             str1W = buf1W;
         else
@@ -3017,7 +3017,7 @@ INT WINAPI CompareStringA(LCID lcid, DWORD flags,
 
     if (len2)
     {
-        len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
+        if (len2 <= 130) len2W = MultiByteToWideChar(locale_cp, 0, str2, len2, buf2W, 130);
         if (len2W)
             str2W = buf2W;
         else
diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
index b6198d1..772d13b 100644
--- a/dlls/kernel32/tests/locale.c
+++ b/dlls/kernel32/tests/locale.c
@@ -1466,7 +1466,6 @@ static void test_CompareStringA(void)
     memset(a, 'a', sizeof(a));
     SetLastError(0xdeadbeef);
     ret = CompareStringA(lcid, 0, a, sizeof(a), a, sizeof(a));
-    todo_wine
     ok (GetLastError() == 0xdeadbeef && ret == CSTR_EQUAL,
         "ret %d, error %d, expected value %d\n", ret, GetLastError(), CSTR_EQUAL);
 }
-- 
1.8.2.3
