Juan Lang : crypt32: Test and fix a couple CertAddCertificateContextToStore corner cases.

Alexandre Julliard julliard at wine.codeweavers.com
Wed May 24 04:00:18 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: e1afe33ac7a1d4fef7728d67cd971dc41a6c2093
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=e1afe33ac7a1d4fef7728d67cd971dc41a6c2093

Author: Juan Lang <juan_lang at yahoo.com>
Date:   Tue May 23 21:56:00 2006 -0700

crypt32: Test and fix a couple CertAddCertificateContextToStore corner cases.

---

 dlls/crypt32/store.c       |   13 +++++++++++--
 dlls/crypt32/tests/store.c |   22 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c
index c150229..160cfdd 100644
--- a/dlls/crypt32/store.c
+++ b/dlls/crypt32/store.c
@@ -2044,6 +2044,12 @@ BOOL WINAPI CertAddCertificateContextToS
     TRACE("(%p, %p, %08lx, %p)\n", hCertStore, pCertContext,
      dwAddDisposition, ppStoreContext);
 
+    /* Weird case to pass a test */
+    if (dwAddDisposition == 0)
+    {
+        SetLastError(STATUS_ACCESS_VIOLATION);
+        return FALSE;
+    }
     if (dwAddDisposition != CERT_STORE_ADD_ALWAYS)
     {
         BYTE hashToAdd[20];
@@ -2095,8 +2101,11 @@ BOOL WINAPI CertAddCertificateContextToS
 
     if (toAdd)
     {
-        ret = store->certs.addContext(store, (void *)toAdd, (void *)existing,
-         (const void **)ppStoreContext);
+        if (store)
+            ret = store->certs.addContext(store, (void *)toAdd,
+             (void *)existing, (const void **)ppStoreContext);
+        else if (ppStoreContext)
+            *ppStoreContext = CertDuplicateCertificateContext(toAdd);
         CertFreeCertificateContext(toAdd);
     }
     CertFreeCertificateContext(existing);
diff --git a/dlls/crypt32/tests/store.c b/dlls/crypt32/tests/store.c
index a3624f1..3d487ac 100644
--- a/dlls/crypt32/tests/store.c
+++ b/dlls/crypt32/tests/store.c
@@ -152,6 +152,28 @@ static void testAddCert(void)
         PCCERT_CONTEXT context;
         BOOL ret;
 
+        /* Weird--bad add disposition leads to an access violation in Windows.
+         */
+        ret = CertAddEncodedCertificateToStore(0, X509_ASN_ENCODING, bigCert,
+         sizeof(bigCert), 0, NULL);
+        ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
+         "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", GetLastError());
+        ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
+         bigCert, sizeof(bigCert), 0, NULL);
+        ok(!ret && GetLastError() == STATUS_ACCESS_VIOLATION,
+         "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", GetLastError());
+
+        /* Weird--can add a cert to the NULL store (does this have special
+         * meaning?)
+         */
+        context = NULL;
+        ret = CertAddEncodedCertificateToStore(0, X509_ASN_ENCODING, bigCert,
+         sizeof(bigCert), CERT_STORE_ADD_ALWAYS, &context);
+        ok(ret, "CertAddEncodedCertificateToStore failed: %08lx\n",
+         GetLastError());
+        if (context)
+            CertFreeCertificateContext(context);
+
         ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
          bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, NULL);
         ok(ret, "CertAddEncodedCertificateToStore failed: %08lx\n",




More information about the wine-cvs mailing list