Juan Lang : crypt32: Correct Unicode quoting of BMP strings.

Alexandre Julliard julliard at winehq.org
Wed Oct 20 13:24:38 CDT 2010


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

Author: Juan Lang <juan.lang at gmail.com>
Date:   Tue Oct 19 19:23:50 2010 -0700

crypt32: Correct Unicode quoting of BMP strings.

---

 dlls/crypt32/str.c       |   45 +++++++++++++++++++++++++++++++++++++++------
 dlls/crypt32/tests/str.c |   10 +++++-----
 2 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c
index 1bdba5d..e118000 100644
--- a/dlls/crypt32/str.c
+++ b/dlls/crypt32/str.c
@@ -73,12 +73,12 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
         if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
             needsQuotes = TRUE;
         for (i = 0; i < pValue->cbData; i++)
-	{
+        {
             if (is_quotable_char(pValue->pbData[i]))
                 needsQuotes = TRUE;
             if (pValue->pbData[i] == '"')
                 len += 1;
-	}
+        }
         if (needsQuotes)
             len += 2;
         if (!psz || !csz)
@@ -158,7 +158,7 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
 DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
  LPWSTR psz, DWORD csz)
 {
-    DWORD ret = 0, len, i;
+    DWORD ret = 0, len, i, strLen;
     BOOL needsQuotes = FALSE;
 
     TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
@@ -175,19 +175,18 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
     case CERT_RDN_GRAPHIC_STRING:
     case CERT_RDN_VISIBLE_STRING:
     case CERT_RDN_GENERAL_STRING:
-    case CERT_RDN_BMP_STRING:
         len = pValue->cbData;
         if (pValue->cbData && isspace(pValue->pbData[0]))
             needsQuotes = TRUE;
         if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
             needsQuotes = TRUE;
         for (i = 0; i < pValue->cbData; i++)
-	{
+        {
             if (is_quotable_char(pValue->pbData[i]))
                 needsQuotes = TRUE;
             if (pValue->pbData[i] == '"')
                 len += 1;
-	}
+        }
         if (needsQuotes)
             len += 2;
         if (!psz || !csz)
@@ -209,6 +208,40 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
             ret = ptr - psz;
         }
         break;
+    case CERT_RDN_BMP_STRING:
+        strLen = len = pValue->cbData / sizeof(WCHAR);
+        if (pValue->cbData && isspace(pValue->pbData[0]))
+            needsQuotes = TRUE;
+        if (pValue->cbData && isspace(pValue->pbData[strLen - 1]))
+            needsQuotes = TRUE;
+        for (i = 0; i < strLen; i++)
+        {
+            if (is_quotable_char(((LPCWSTR)pValue->pbData)[i]))
+                needsQuotes = TRUE;
+            if (((LPCWSTR)pValue->pbData)[i] == '"')
+                len += 1;
+        }
+        if (needsQuotes)
+            len += 2;
+        if (!psz || !csz)
+            ret = len;
+        else
+        {
+            WCHAR *ptr = psz;
+
+            if (needsQuotes)
+                *ptr++ = '"';
+            for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++)
+            {
+                *ptr = ((LPCWSTR)pValue->pbData)[i];
+                if (((LPCWSTR)pValue->pbData)[i] == '"' && ptr - psz < csz - 1)
+                    *(++ptr) = '"';
+            }
+            if (needsQuotes && ptr - psz < csz)
+                *ptr++ = '"';
+            ret = ptr - psz;
+        }
+        break;
     default:
         FIXME("string type %d unimplemented\n", dwValueType);
     }
diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c
index 913599e..b9af4cd 100644
--- a/dlls/crypt32/tests/str.c
+++ b/dlls/crypt32/tests/str.c
@@ -570,7 +570,7 @@ static void test_CertNameToStrW(void)
     blob.pbData = encodedQuotedCN;
     blob.cbData = sizeof(encodedQuotedCN);
     test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, quotedCN_W,
-     TRUE);
+     FALSE);
     blob.pbData = encodedMultipleAttrCN;
     blob.cbData = sizeof(encodedMultipleAttrCN);
     test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, multipleAttrCN_W,
@@ -583,17 +583,17 @@ static void test_CertNameToStrW(void)
     test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, equalCN_W, FALSE);
     blob.pbData = encodedLessThanCN;
     blob.cbData = sizeof(encodedLessThanCN);
-    test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, TRUE);
+    test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, FALSE);
     blob.pbData = encodedGreaterThanCN;
     blob.cbData = sizeof(encodedGreaterThanCN);
     test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, greaterThanCN_W,
-     TRUE);
+     FALSE);
     blob.pbData = encodedHashCN;
     blob.cbData = sizeof(encodedHashCN);
-    test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, TRUE);
+    test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, FALSE);
     blob.pbData = encodedSemiCN;
     blob.cbData = sizeof(encodedSemiCN);
-    test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, TRUE);
+    test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, FALSE);
 }
 
 struct StrToNameA




More information about the wine-cvs mailing list