Juan Lang : crypt32: Fail if MultiByteToWideChar converts 0 characters.

Alexandre Julliard julliard at winehq.org
Mon Oct 22 09:55:29 CDT 2007


Module: wine
Branch: master
Commit: 7cf611ef3bae6340e6c7fce10e45ef9843f117fd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7cf611ef3bae6340e6c7fce10e45ef9843f117fd

Author: Juan Lang <juan.lang at gmail.com>
Date:   Sat Oct 20 14:22:04 2007 -0700

crypt32: Fail if MultiByteToWideChar converts 0 characters.

---

 dlls/crypt32/str.c |   38 ++++++++++++++++++++++++++------------
 1 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c
index 96430dc..9677897 100644
--- a/dlls/crypt32/str.c
+++ b/dlls/crypt32/str.c
@@ -455,7 +455,6 @@ BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500,
  DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded,
  LPCSTR *ppszError)
 {
-    LPWSTR x500, errorStr;
     BOOL ret;
     int len;
 
@@ -464,24 +463,39 @@ BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500,
      ppszError);
 
     len = MultiByteToWideChar(CP_ACP, 0, pszX500, -1, NULL, 0);
-    x500 = CryptMemAlloc(len * sizeof(WCHAR));
-    if (x500)
+    if (len)
     {
-        MultiByteToWideChar(CP_ACP, 0, pszX500, -1, x500, len);
-        ret = CertStrToNameW(dwCertEncodingType, x500, dwStrType, pvReserved,
-         pbEncoded, pcbEncoded, ppszError ? (LPCWSTR *)&errorStr : NULL);
-        if (ppszError)
+        LPWSTR x500, errorStr;
+
+        if ((x500 = CryptMemAlloc(len * sizeof(WCHAR))))
         {
-            DWORD i;
+            MultiByteToWideChar(CP_ACP, 0, pszX500, -1, x500, len);
+            ret = CertStrToNameW(dwCertEncodingType, x500, dwStrType,
+             pvReserved, pbEncoded, pcbEncoded,
+             ppszError ? (LPCWSTR *)&errorStr : NULL);
+            if (ppszError)
+            {
+                DWORD i;
 
-            *ppszError = pszX500;
-            for (i = 0; i < errorStr - x500; i++)
-                *ppszError = CharNextA(*ppszError);
+                *ppszError = pszX500;
+                for (i = 0; i < errorStr - x500; i++)
+                    *ppszError = CharNextA(*ppszError);
+            }
+            CryptMemFree(x500);
+        }
+        else
+        {
+            SetLastError(ERROR_OUTOFMEMORY);
+            ret = FALSE;
         }
-        CryptMemFree(x500);
     }
     else
+    {
+        SetLastError(CRYPT_E_INVALID_X500_STRING);
+        if (ppszError)
+            *ppszError = pszX500;
         ret = FALSE;
+    }
     return ret;
 }
 




More information about the wine-cvs mailing list