diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c index f2889f9fec0..f23629ba116 100644 --- a/dlls/crypt32/cert.c +++ b/dlls/crypt32/cert.c @@ -129,14 +129,12 @@ static context_t *Cert_clone(context_t *context, WINECRYPT_CERTSTORE *store, BOO return NULL; }else { const cert_t *cloned = (const cert_t*)context; - void *new_context; DWORD size = 0; BOOL res; - new_context = Context_CreateDataContext(sizeof(CERT_CONTEXT), &cert_vtbl, store); - if(!new_context) + cert = (cert_t*)Context_CreateDataContext(sizeof(CERT_CONTEXT), &cert_vtbl, store); + if(!cert) return NULL; - cert = cert_from_ptr(new_context); Context_CopyProperties(&cert->ctx, &cloned->ctx); @@ -312,7 +310,8 @@ BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore, PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, const BYTE *pbCertEncoded, DWORD cbCertEncoded) { - PCERT_CONTEXT cert = NULL; + cert_t *cert = NULL; + BYTE *data = NULL; BOOL ret; PCERT_INFO certInfo = NULL; DWORD size = 0; @@ -329,30 +328,27 @@ PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, ret = CryptDecodeObjectEx(dwCertEncodingType, X509_CERT_TO_BE_SIGNED, pbCertEncoded, cbCertEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &certInfo, &size); - if (ret) - { - BYTE *data = NULL; + if (!ret) + return NULL; - cert = Context_CreateDataContext(sizeof(CERT_CONTEXT), &cert_vtbl, &empty_store); - if (!cert) - goto end; - data = CryptMemAlloc(cbCertEncoded); - if (!data) - { - CertFreeCertificateContext(cert); - cert = NULL; - goto end; - } - memcpy(data, pbCertEncoded, cbCertEncoded); - cert->dwCertEncodingType = dwCertEncodingType; - cert->pbCertEncoded = data; - cert->cbCertEncoded = cbCertEncoded; - cert->pCertInfo = certInfo; - cert->hCertStore = &empty_store; + cert = (cert_t*)Context_CreateDataContext(sizeof(CERT_CONTEXT), &cert_vtbl, &empty_store); + if (!cert) + return NULL; + data = CryptMemAlloc(cbCertEncoded); + if (!data) + { + Context_Release(&cert->base); + return NULL; } -end: - return cert; + memcpy(data, pbCertEncoded, cbCertEncoded); + cert->ctx.dwCertEncodingType = dwCertEncodingType; + cert->ctx.pbCertEncoded = data; + cert->ctx.cbCertEncoded = cbCertEncoded; + cert->ctx.pCertInfo = certInfo; + cert->ctx.hCertStore = &empty_store; + + return &cert->ctx; } PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext) diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c index 6dc46c2c012..9c26439f5e9 100644 --- a/dlls/crypt32/context.c +++ b/dlls/crypt32/context.c @@ -25,7 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(context); -void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl, WINECRYPT_CERTSTORE *store) +context_t *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl, WINECRYPT_CERTSTORE *store) { context_t *context; @@ -48,7 +48,7 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl, context->store = store; TRACE("returning %p\n", context); - return context_ptr(context); + return context; } context_t *Context_CreateLinkContext(unsigned int contextSize, context_t *linked, WINECRYPT_CERTSTORE *store) diff --git a/dlls/crypt32/crl.c b/dlls/crypt32/crl.c index 8eb587aec68..07e86b21f0b 100644 --- a/dlls/crypt32/crl.c +++ b/dlls/crypt32/crl.c @@ -49,14 +49,12 @@ static context_t *CRL_clone(context_t *context, WINECRYPT_CERTSTORE *store, BOOL return NULL; }else { const crl_t *cloned = (const crl_t*)context; - void *new_context; DWORD size = 0; BOOL res; - new_context = Context_CreateDataContext(sizeof(CRL_CONTEXT), &crl_vtbl, store); - if(!new_context) + crl = (crl_t*)Context_CreateDataContext(sizeof(CRL_CONTEXT), &crl_vtbl, store); + if(!crl) return NULL; - crl = crl_from_ptr(new_context); Context_CopyProperties(&crl->ctx, &cloned->ctx); @@ -87,9 +85,10 @@ static const context_vtbl_t crl_vtbl = { PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType, const BYTE* pbCrlEncoded, DWORD cbCrlEncoded) { - PCRL_CONTEXT crl = NULL; + crl_t *crl = NULL; BOOL ret; PCRL_INFO crlInfo = NULL; + BYTE *data = NULL; DWORD size = 0; TRACE("(%08x, %p, %d)\n", dwCertEncodingType, pbCrlEncoded, @@ -103,30 +102,28 @@ PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType, ret = CryptDecodeObjectEx(dwCertEncodingType, X509_CERT_CRL_TO_BE_SIGNED, pbCrlEncoded, cbCrlEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &crlInfo, &size); - if (ret) - { - BYTE *data = NULL; + if (!ret) + return NULL; - crl = Context_CreateDataContext(sizeof(CRL_CONTEXT), &crl_vtbl, &empty_store); - if (!crl) - goto end; - data = CryptMemAlloc(cbCrlEncoded); - if (!data) - { - CertFreeCRLContext(crl); - crl = NULL; - goto end; - } - memcpy(data, pbCrlEncoded, cbCrlEncoded); - crl->dwCertEncodingType = dwCertEncodingType; - crl->pbCrlEncoded = data; - crl->cbCrlEncoded = cbCrlEncoded; - crl->pCrlInfo = crlInfo; - crl->hCertStore = &empty_store; + crl = (crl_t*)Context_CreateDataContext(sizeof(CRL_CONTEXT), &crl_vtbl, &empty_store); + if (!crl) + return NULL; + + data = CryptMemAlloc(cbCrlEncoded); + if (!data) + { + Context_Release(&crl->base); + return NULL; } -end: - return crl; + memcpy(data, pbCrlEncoded, cbCrlEncoded); + crl->ctx.dwCertEncodingType = dwCertEncodingType; + crl->ctx.pbCrlEncoded = data; + crl->ctx.cbCrlEncoded = cbCrlEncoded; + crl->ctx.pCrlInfo = crlInfo; + crl->ctx.hCertStore = &empty_store; + + return &crl->ctx; } BOOL WINAPI CertAddEncodedCRLToStore(HCERTSTORE hCertStore, diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index 2dbc1ce3858..53e08340160 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -389,7 +389,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indent, * which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT. * Free with Context_Release. */ -void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl, struct WINE_CRYPTCERTSTORE*) DECLSPEC_HIDDEN; +context_t *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl, struct WINE_CRYPTCERTSTORE*) DECLSPEC_HIDDEN; /* Creates a new link context. The context refers to linked * rather than owning its own properties. If addRef is TRUE (which ordinarily diff --git a/dlls/crypt32/ctl.c b/dlls/crypt32/ctl.c index 7a8c21f9f0b..6893e2d4274 100644 --- a/dlls/crypt32/ctl.c +++ b/dlls/crypt32/ctl.c @@ -367,7 +367,7 @@ BOOL WINAPI CertDeleteCTLFromStore(PCCTL_CONTEXT pCtlContext) PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType, const BYTE *pbCtlEncoded, DWORD cbCtlEncoded) { - PCTL_CONTEXT ctl = NULL; + ctl_t *ctl = NULL; HCRYPTMSG msg; BOOL ret; BYTE *content = NULL; @@ -440,7 +440,7 @@ PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType, &ctlInfo, &size); if (ret) { - ctl = Context_CreateDataContext(sizeof(CTL_CONTEXT), &ctl_vtbl, &empty_store); + ctl = (ctl_t*)Context_CreateDataContext(sizeof(CTL_CONTEXT), &ctl_vtbl, &empty_store); if (ctl) { BYTE *data = CryptMemAlloc(cbCtlEncoded); @@ -448,15 +448,15 @@ PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType, if (data) { memcpy(data, pbCtlEncoded, cbCtlEncoded); - ctl->dwMsgAndCertEncodingType = + ctl->ctx.dwMsgAndCertEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING; - ctl->pbCtlEncoded = data; - ctl->cbCtlEncoded = cbCtlEncoded; - ctl->pCtlInfo = ctlInfo; - ctl->hCertStore = &empty_store; - ctl->hCryptMsg = msg; - ctl->pbCtlContext = content; - ctl->cbCtlContext = contentSize; + ctl->ctx.pbCtlEncoded = data; + ctl->ctx.cbCtlEncoded = cbCtlEncoded; + ctl->ctx.pCtlInfo = ctlInfo; + ctl->ctx.hCertStore = &empty_store; + ctl->ctx.hCryptMsg = msg; + ctl->ctx.pbCtlContext = content; + ctl->ctx.cbCtlContext = contentSize; } else { @@ -481,13 +481,15 @@ PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType, end: if (!ret) { - CertFreeCTLContext(ctl); + if(ctl) + Context_Release(&ctl->base); ctl = NULL; LocalFree(ctlInfo); CryptMemFree(content); CryptMsgClose(msg); + return NULL; } - return ctl; + return &ctl->ctx; } PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext)