[PATCH 4/4] kernel32: dstlen < 0 causes ERROR_INVALID_PARAMETER in MultiByteToWideChar and WideCharToMultiByte

Alex Henrie alexhenrie24 at gmail.com
Sun Dec 2 22:13:44 CST 2012


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

diff --git a/dlls/kernel32/locale.c b/dlls/kernel32/locale.c
index 4dc6e54..c4f2d43 100644
--- a/dlls/kernel32/locale.c
+++ b/dlls/kernel32/locale.c
@@ -2161,7 +2161,7 @@ INT WINAPI MultiByteToWideChar( UINT page, DWORD flags, LPCSTR src, INT srclen,
     const union cptable *table;
     int ret;
 
-    if (!src || !srclen || (!dst && dstlen))
+    if (!src || !srclen || (!dst && dstlen) || dstlen < 0)
     {
         SetLastError( ERROR_INVALID_PARAMETER );
         return 0;
@@ -2514,7 +2514,7 @@ INT WINAPI WideCharToMultiByte( UINT page, DWORD flags, LPCWSTR src, INT srclen,
     const union cptable *table;
     int ret, used_tmp;
 
-    if (!src || !srclen || (!dst && dstlen))
+    if (!src || !srclen || (!dst && dstlen) || dstlen < 0)
     {
         SetLastError( ERROR_INVALID_PARAMETER );
         return 0;
diff --git a/dlls/kernel32/tests/codepage.c b/dlls/kernel32/tests/codepage.c
index f920158..5d01ab4 100644
--- a/dlls/kernel32/tests/codepage.c
+++ b/dlls/kernel32/tests/codepage.c
@@ -152,19 +152,15 @@ static void test_negative_dest_length(void)
     SetLastError( 0xdeadbeef );
     memset(buf,'x',sizeof(buf));
     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, -1, NULL, NULL);
-    todo_wine {
-      ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
-         "WideCharToMultiByte(destlen -1): len=%d error=%x\n", len, GetLastError());
-    }
+    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
+       "WideCharToMultiByte(destlen -1): len=%d error=%x\n", len, GetLastError());
 
     /* Test return on -1000 dest length */
     SetLastError( 0xdeadbeef );
     memset(buf,'x',sizeof(buf));
     len = WideCharToMultiByte(CP_ACP, 0, foobarW, -1, buf, -1000, NULL, NULL);
-    todo_wine {
-      ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
-         "WideCharToMultiByte(destlen -1000): len=%d error=%x\n", len, GetLastError());
-    }
+    ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER,
+       "WideCharToMultiByte(destlen -1000): len=%d error=%x\n", len, GetLastError());
 
     /* Test return on INT_MAX dest length */
     SetLastError( 0xdeadbeef );
-- 
1.7.10.4



More information about the wine-patches mailing list