crypt32(2/6): Fix typo in key context property test, and the problems it hid

Juan Lang juan.lang at gmail.com
Thu Aug 2 14:32:55 CDT 2007


--Juan
-------------- next part --------------
From 807ff540ee6029f042370d0f430f47a847d806f2 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Thu, 2 Aug 2007 12:21:46 -0700
Subject: [PATCH] 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_SetProper
             {
                 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);
 }
 
-- 
1.4.1


More information about the wine-patches mailing list