Juan Lang : crypt32: Fix typo in key context property test, and the problems it hid.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Aug 3 08:04:36 CDT 2007


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

Author: Juan Lang <juan.lang at gmail.com>
Date:   Thu Aug  2 12:21:46 2007 -0700

crypt32: Fix typo in key context property test, and the problems it hid.

---

 dlls/crypt32/cert.c       |   10 +++++-
 dlls/crypt32/tests/cert.c |   63 +++++++++++++++++---------------------------
 2 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index b630f3d..a74e5e4 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -476,8 +476,14 @@ static BOOL WINAPI CertContext_SetProperty(void *context, DWORD dwPropId,
             {
                 const CERT_KEY_CONTEXT *keyContext = (const CERT_KEY_CONTEXT *)pvData;
 
-                ret = ContextPropertyList_SetProperty(properties, dwPropId,
-                 (const BYTE *)keyContext, keyContext->cbSize);
+                if (keyContext->cbSize != sizeof(CERT_KEY_CONTEXT))
+                {
+                    SetLastError(E_INVALIDARG);
+                    ret = FALSE;
+                }
+                else
+                    ret = ContextPropertyList_SetProperty(properties, dwPropId,
+                     (const BYTE *)keyContext, keyContext->cbSize);
             }
             else
             {
diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
index a14137c..4231a1e 100644
--- a/dlls/crypt32/tests/cert.c
+++ b/dlls/crypt32/tests/cert.c
@@ -334,7 +334,6 @@ static void testCertProperties(void)
     BYTE hash[20] = { 0 }, hashProperty[20];
     CRYPT_DATA_BLOB blob;
     CERT_KEY_CONTEXT keyContext;
-    HCRYPTPROV csp;
 
     ok(context != NULL, "CertCreateCertificateContext failed: %08x\n",
      GetLastError());
@@ -442,50 +441,38 @@ static void testCertProperties(void)
      context->pCertInfo->SubjectPublicKeyInfo.PublicKey.cbData,
      CALG_MD5, context, CERT_SUBJECT_PUBLIC_KEY_MD5_HASH_PROP_ID);
 
-    /* Test key identifiers and handles and such */
+    /* Test key contexts and handles and such */
     size = 0;
-    ret = CertGetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, NULL, &size);
-    ok(!ret && GetLastError() == ERROR_INVALID_DATA,
-     "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
+    ret = CertGetCertificateContextProperty(context, CERT_KEY_CONTEXT_PROP_ID,
+     NULL, &size);
+    ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
+     "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
     size = sizeof(CERT_KEY_CONTEXT);
-    ret = CertGetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, NULL, &size);
-    ok(!ret && GetLastError() == ERROR_INVALID_DATA,
-     "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
-    ret = CertGetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, &keyContext, &size);
-    ok(!ret && GetLastError() == ERROR_INVALID_DATA,
-     "Expected ERROR_INVALID_DATA, got %08x\n", GetLastError());
+    ret = CertGetCertificateContextProperty(context, CERT_KEY_CONTEXT_PROP_ID,
+     NULL, &size);
+    ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
+     "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
+    ret = CertGetCertificateContextProperty(context, CERT_KEY_CONTEXT_PROP_ID,
+     &keyContext, &size);
+    ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
+     "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
     /* Key context with an invalid size */
     keyContext.cbSize = 0;
-    ret = CertSetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, 0, &keyContext);
-    ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
-     GetLastError());
+    ret = CertSetCertificateContextProperty(context, CERT_KEY_CONTEXT_PROP_ID,
+     0, &keyContext);
+    ok(!ret && GetLastError() == E_INVALIDARG,
+     "Expected E_INVALIDARG, got %08x\n", GetLastError());
     size = sizeof(keyContext);
-    ret = CertGetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, &keyContext, &size);
-    ok(ret, "CertGetCertificateContextProperty failed: %08x\n",
-     GetLastError());
+    ret = CertGetCertificateContextProperty(context, CERT_KEY_CONTEXT_PROP_ID,
+     &keyContext, &size);
+    ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND,
+     "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError());
     keyContext.cbSize = sizeof(keyContext);
     keyContext.hCryptProv = 0;
     keyContext.dwKeySpec = AT_SIGNATURE;
-    /* Crash
-    ret = CertSetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, 0, &keyContext);
-    ret = CertSetCertificateContextProperty(context,
-     CERT_KEY_IDENTIFIER_PROP_ID, CERT_STORE_NO_CRYPT_RELEASE_FLAG,
-     &keyContext);
-     */
-    ret = CryptAcquireContextW(&csp, cspNameW,
-     MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_NEWKEYSET);
-    ok(ret, "CryptAcquireContextW failed: %08x\n", GetLastError());
-    keyContext.hCryptProv = csp;
-    ret = CertSetCertificateContextProperty(context,
-     CERT_KEY_CONTEXT_PROP_ID, 0, &keyContext);
-    ok(ret, "CertSetCertificateContextProperty failed: %08x\n",
-     GetLastError());
+    ret = CertSetCertificateContextProperty(context, CERT_KEY_CONTEXT_PROP_ID,
+     0, &keyContext);
+    ok(ret, "CertSetCertificateContextProperty failed: %08x\n", GetLastError());
     /* Now that that's set, the key prov handle property is also gettable.
      */
     size = sizeof(DWORD);
@@ -506,8 +493,6 @@ static void testCertProperties(void)
      GetLastError());
     ok(keyContext.hCryptProv == 0, "Expected no hCryptProv\n");
 
-    CryptReleaseContext(csp, 0);
-
     CertFreeCertificateContext(context);
 }
 




More information about the wine-cvs mailing list