Use single buffer for returned certificate blobs, instead of an array of CERT_BLOB that contains pointers.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel.c | 18 +++++++++++------- dlls/secur32/schannel_gnutls.c | 14 +++++++------- dlls/secur32/secur32_priv.h | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 6ab5507becf..2e663872f71 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -1026,7 +1026,6 @@ static SECURITY_STATUS ensure_remote_cert(struct schan_context *ctx) HCERTSTORE store; PCCERT_CONTEXT cert = NULL; SECURITY_STATUS status; - CERT_BLOB *certs; ULONG count, size = 0; struct get_session_peer_certificate_params params = { ctx->transport.session, NULL, &size, &count };
@@ -1036,28 +1035,33 @@ static SECURITY_STATUS ensure_remote_cert(struct schan_context *ctx)
status = GNUTLS_CALL( get_session_peer_certificate, ¶ms ); if (status != SEC_E_BUFFER_TOO_SMALL) goto done; - if (!(certs = malloc( size ))) + if (!(params.buffer = malloc( size ))) { status = SEC_E_INSUFFICIENT_MEMORY; goto done; } - params.certs = certs; status = GNUTLS_CALL( get_session_peer_certificate, ¶ms ); if (status == SEC_E_OK) { unsigned int i; + ULONG *sizes; + BYTE *blob; + + sizes = (ULONG *)params.buffer; + blob = params.buffer + count * sizeof(*sizes); + for (i = 0; i < count; i++) { - if (!CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, certs[i].pbData, - certs[i].cbData, CERT_STORE_ADD_REPLACE_EXISTING, - i ? NULL : &cert)) + if (!CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, blob, sizes[i], + CERT_STORE_ADD_REPLACE_EXISTING, i ? NULL : &cert)) { if (i) CertFreeCertificateContext(cert); return GetLastError(); } + blob += sizes[i]; } } - free(certs); + free(params.buffer); done: ctx->cert = cert; CertCloseStore(store, 0); diff --git a/dlls/secur32/schannel_gnutls.c b/dlls/secur32/schannel_gnutls.c index 0145c59e0f0..7c6a0bc0cfc 100644 --- a/dlls/secur32/schannel_gnutls.c +++ b/dlls/secur32/schannel_gnutls.c @@ -792,28 +792,28 @@ static NTSTATUS schan_get_session_peer_certificate( void *args ) { const struct get_session_peer_certificate_params *params = args; gnutls_session_t s = (gnutls_session_t)params->session; - CERT_BLOB *certs = params->certs; const gnutls_datum_t *datum; unsigned int i, size; BYTE *ptr; unsigned int count; + ULONG *sizes;
if (!(datum = pgnutls_certificate_get_peers(s, &count))) return SEC_E_INTERNAL_ERROR;
- size = count * sizeof(certs[0]); + size = count * sizeof(*sizes); for (i = 0; i < count; i++) size += datum[i].size;
- if (!certs || *params->bufsize < size) + if (!params->buffer || *params->bufsize < size) { *params->bufsize = size; return SEC_E_BUFFER_TOO_SMALL; } - ptr = (BYTE *)&certs[count]; + sizes = (ULONG *)params->buffer; + ptr = params->buffer + count * sizeof(*sizes); for (i = 0; i < count; i++) { - certs[i].cbData = datum[i].size; - certs[i].pbData = ptr; - memcpy(certs[i].pbData, datum[i].data, datum[i].size); + sizes[i] = datum[i].size; + memcpy(ptr, datum[i].data, datum[i].size); ptr += datum[i].size; }
diff --git a/dlls/secur32/secur32_priv.h b/dlls/secur32/secur32_priv.h index be375618266..5c35e4244c8 100644 --- a/dlls/secur32/secur32_priv.h +++ b/dlls/secur32/secur32_priv.h @@ -145,7 +145,7 @@ struct get_connection_info_params struct get_session_peer_certificate_params { schan_session session; - CERT_BLOB *certs; + BYTE *buffer; /* Starts with array of ULONG sizes, followed by contiguous data blob. */ ULONG *bufsize; ULONG *retcount; };
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel_gnutls.c | 42 +++++++++++++++++++--------------- dlls/secur32/secur32_priv.h | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/dlls/secur32/schannel_gnutls.c b/dlls/secur32/schannel_gnutls.c index 7c6a0bc0cfc..cfc7907bef4 100644 --- a/dlls/secur32/schannel_gnutls.c +++ b/dlls/secur32/schannel_gnutls.c @@ -136,6 +136,11 @@ MAKE_FUNCPTR(gnutls_x509_privkey_deinit); #define GNUTLS_ALPN_SERVER_PRECEDENCE (1<<1) #endif
+static inline gnutls_session_t session_from_handle(UINT64 handle) +{ + return (gnutls_session_t)(ULONG_PTR)handle; +} + static int compat_cipher_get_block_size(gnutls_cipher_algorithm_t cipher) { switch(cipher) { @@ -369,7 +374,7 @@ static char *get_buffer(const struct schan_transport *t, struct schan_buffers *s static ssize_t pull_adapter(gnutls_transport_ptr_t transport, void *buff, size_t buff_len) { struct schan_transport *t = (struct schan_transport*)transport; - gnutls_session_t s = (gnutls_session_t)t->session; + gnutls_session_t s = session_from_handle(t->session); SIZE_T len = buff_len; char *b;
@@ -390,7 +395,7 @@ static ssize_t pull_adapter(gnutls_transport_ptr_t transport, void *buff, size_t static ssize_t push_adapter(gnutls_transport_ptr_t transport, const void *buff, size_t buff_len) { struct schan_transport *t = (struct schan_transport*)transport; - gnutls_session_t s = (gnutls_session_t)t->session; + gnutls_session_t s = session_from_handle(t->session); SIZE_T len = buff_len; char *b;
@@ -547,7 +552,7 @@ static NTSTATUS schan_create_session( void *args ) static NTSTATUS schan_dispose_session( void *args ) { const struct session_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); pgnutls_deinit(s); return STATUS_SUCCESS; } @@ -555,7 +560,7 @@ static NTSTATUS schan_dispose_session( void *args ) static NTSTATUS schan_set_session_target( void *args ) { const struct set_session_target_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); pgnutls_server_name_set( s, GNUTLS_NAME_DNS, params->target, strlen(params->target) ); return STATUS_SUCCESS; } @@ -563,7 +568,7 @@ static NTSTATUS schan_set_session_target( void *args ) static NTSTATUS schan_handshake( void *args ) { const struct handshake_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); struct schan_transport *t = (struct schan_transport *)pgnutls_transport_get_ptr(s); int err;
@@ -709,20 +714,21 @@ static ALG_ID get_kx_algid(int kx) static NTSTATUS schan_get_session_cipher_block_size( void *args ) { const struct session_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); return pgnutls_cipher_get_block_size(pgnutls_cipher_get(s)); }
static NTSTATUS schan_get_max_message_size( void *args ) { const struct session_params *params = args; - return pgnutls_record_get_max_size((gnutls_session_t)params->session); + gnutls_session_t s = session_from_handle(params->session); + return pgnutls_record_get_max_size(s); }
static NTSTATUS schan_get_connection_info( void *args ) { const struct get_connection_info_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); SecPkgContext_ConnectionInfo *info = params->info; gnutls_protocol_t proto = pgnutls_protocol_get_version(s); gnutls_cipher_algorithm_t alg = pgnutls_cipher_get(s); @@ -743,10 +749,10 @@ static NTSTATUS schan_get_connection_info( void *args ) static NTSTATUS schan_get_unique_channel_binding( void *args ) { const struct get_unique_channel_binding_params *params = args; + gnutls_session_t s = session_from_handle(params->session); gnutls_datum_t datum; int rc; SECURITY_STATUS ret; - gnutls_session_t s = (gnutls_session_t)params->session;
rc = pgnutls_session_channel_binding(s, GNUTLS_CB_TLS_UNIQUE, &datum); if (rc) @@ -769,10 +775,10 @@ static NTSTATUS schan_get_unique_channel_binding( void *args ) static NTSTATUS schan_get_key_signature_algorithm( void *args ) { const struct session_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); gnutls_kx_algorithm_t kx = pgnutls_kx_get(s);
- TRACE("(%p)\n", params->session); + TRACE("(%p)\n", s);
switch (kx) { @@ -791,7 +797,7 @@ static NTSTATUS schan_get_key_signature_algorithm( void *args ) static NTSTATUS schan_get_session_peer_certificate( void *args ) { const struct get_session_peer_certificate_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); const gnutls_datum_t *datum; unsigned int i, size; BYTE *ptr; @@ -825,7 +831,7 @@ static NTSTATUS schan_get_session_peer_certificate( void *args ) static NTSTATUS schan_send( void *args ) { const struct send_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); struct schan_transport *t = (struct schan_transport *)pgnutls_transport_get_ptr(s); SSIZE_T ret, total = 0;
@@ -864,7 +870,7 @@ static NTSTATUS schan_send( void *args ) static NTSTATUS schan_recv( void *args ) { const struct recv_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); struct schan_transport *t = (struct schan_transport *)pgnutls_transport_get_ptr(s); size_t data_size = *params->length; size_t received = 0; @@ -928,7 +934,7 @@ static unsigned int parse_alpn_protocol_list(unsigned char *buffer, unsigned int static NTSTATUS schan_set_application_protocols( void *args ) { const struct set_application_protocols_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); unsigned int extension_len, extension, count = 0, offset = 0; unsigned short list_len; gnutls_datum_t *protocols; @@ -968,7 +974,7 @@ static NTSTATUS schan_set_application_protocols( void *args ) static NTSTATUS schan_get_application_protocol( void *args ) { const struct get_application_protocol_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session); SecPkgContext_ApplicationProtocol *protocol = params->protocol; gnutls_datum_t selected;
@@ -989,7 +995,7 @@ static NTSTATUS schan_get_application_protocol( void *args ) static NTSTATUS schan_set_dtls_mtu( void *args ) { const struct set_dtls_mtu_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session);
pgnutls_dtls_set_mtu(s, params->mtu); TRACE("MTU set to %u\n", params->mtu); @@ -999,7 +1005,7 @@ static NTSTATUS schan_set_dtls_mtu( void *args ) static NTSTATUS schan_set_dtls_timeouts( void *args ) { const struct set_dtls_timeouts_params *params = args; - gnutls_session_t s = (gnutls_session_t)params->session; + gnutls_session_t s = session_from_handle(params->session);
pgnutls_dtls_set_timeouts(s, params->retrans_timeout, params->total_timeout); return SEC_E_OK; diff --git a/dlls/secur32/secur32_priv.h b/dlls/secur32/secur32_priv.h index 5c35e4244c8..814d9faf82a 100644 --- a/dlls/secur32/secur32_priv.h +++ b/dlls/secur32/secur32_priv.h @@ -79,7 +79,7 @@ void load_auth_packages(void) DECLSPEC_HIDDEN; void SECUR32_deinitSchannelSP(void) DECLSPEC_HIDDEN;
/* schannel internal interface */ -typedef struct schan_session_opaque *schan_session; +typedef UINT64 schan_session;
typedef struct schan_credentials {
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel.c | 21 ++++++++++++++------- dlls/secur32/schannel_gnutls.c | 23 +++++++++++------------ dlls/secur32/secur32_priv.h | 7 +++++-- 3 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 2e663872f71..5d6e8763095 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -545,8 +545,9 @@ static SECURITY_STATUS schan_AcquireClientCredentials(const void *schanCred, ULONG_PTR handle; SECURITY_STATUS status = SEC_E_OK; const CERT_CONTEXT *cert = NULL; - DATA_BLOB key_blob = {0}; - struct allocate_certificate_credentials_params params; + struct allocate_certificate_credentials_params params = { 0 }; + BYTE *key_blob = NULL; + ULONG key_size = 0;
TRACE("schanCred %p, phCredential %p, ptsExpiry %p\n", schanCred, phCredential, ptsExpiry);
@@ -581,12 +582,18 @@ static SECURITY_STATUS schan_AcquireClientCredentials(const void *schanCred, creds->credential_use = SECPKG_CRED_OUTBOUND; creds->enabled_protocols = enabled_protocols;
- if (cert && !(key_blob.pbData = get_key_blob(cert, &key_blob.cbData))) goto fail; + if (cert && !(key_blob = get_key_blob(cert, &key_size))) goto fail; params.c = creds; - params.ctx = cert; - params.key_blob = &key_blob; + if (cert) + { + params.cert_encoding = cert->dwCertEncodingType; + params.cert_size = cert->cbCertEncoded; + params.cert_blob = cert->pbCertEncoded; + } + params.key_size = key_size; + params.key_blob = key_blob; if (GNUTLS_CALL( allocate_certificate_credentials, ¶ms )) goto fail; - RtlFreeHeap(GetProcessHeap(), 0, key_blob.pbData); + RtlFreeHeap(GetProcessHeap(), 0, key_blob);
handle = schan_alloc_handle(creds, SCHAN_HANDLE_CRED); if (handle == SCHAN_INVALID_HANDLE) goto fail; @@ -605,7 +612,7 @@ static SECURITY_STATUS schan_AcquireClientCredentials(const void *schanCred,
fail: free(creds); - RtlFreeHeap(GetProcessHeap(), 0, key_blob.pbData); + RtlFreeHeap(GetProcessHeap(), 0, key_blob); return SEC_E_INTERNAL_ERROR; }
diff --git a/dlls/secur32/schannel_gnutls.c b/dlls/secur32/schannel_gnutls.c index cfc7907bef4..131b40a45d3 100644 --- a/dlls/secur32/schannel_gnutls.c +++ b/dlls/secur32/schannel_gnutls.c @@ -1038,19 +1038,19 @@ static ULONG set_component(gnutls_datum_t *comp, BYTE *data, ULONG len, ULONG *b return comp->size; }
-static gnutls_x509_privkey_t get_x509_key(const DATA_BLOB *key_blob) +static gnutls_x509_privkey_t get_x509_key(ULONG key_size, const BYTE *key_blob) { gnutls_privkey_t key = NULL; gnutls_x509_privkey_t x509key = NULL; gnutls_datum_t m, e, d, p, q, u, e1, e2; BYTE *ptr; RSAPUBKEY *rsakey; - DWORD size = key_blob->cbData; + DWORD size = key_size; int ret;
if (size < sizeof(BLOBHEADER)) return NULL;
- rsakey = (RSAPUBKEY *)(key_blob->pbData + sizeof(BLOBHEADER)); + rsakey = (RSAPUBKEY *)(key_blob + sizeof(BLOBHEADER)); TRACE("RSA key bitlen %u pubexp %u\n", (unsigned)rsakey->bitlen, (unsigned)rsakey->pubexp);
size -= sizeof(BLOBHEADER) + FIELD_OFFSET(RSAPUBKEY, pubexp); @@ -1082,16 +1082,15 @@ static gnutls_x509_privkey_t get_x509_key(const DATA_BLOB *key_blob) return x509key; }
-static gnutls_x509_crt_t get_x509_crt(const CERT_CONTEXT *ctx) +static gnutls_x509_crt_t get_x509_crt(const struct allocate_certificate_credentials_params *params) { gnutls_datum_t data; gnutls_x509_crt_t crt; int ret;
- if (!ctx) return FALSE; - if (ctx->dwCertEncodingType != X509_ASN_ENCODING) + if (params->cert_encoding != X509_ASN_ENCODING) { - FIXME("encoding type %u not supported\n", (unsigned)ctx->dwCertEncodingType); + FIXME("encoding type %u not supported\n", (unsigned)params->cert_encoding); return NULL; }
@@ -1101,8 +1100,8 @@ static gnutls_x509_crt_t get_x509_crt(const CERT_CONTEXT *ctx) return NULL; }
- data.data = ctx->pbCertEncoded; - data.size = ctx->cbCertEncoded; + data.data = params->cert_blob; + data.size = params->cert_size; if ((ret = pgnutls_x509_crt_import(crt, &data, GNUTLS_X509_FMT_DER)) < 0) { pgnutls_perror(ret); @@ -1128,19 +1127,19 @@ static NTSTATUS schan_allocate_certificate_credentials( void *args ) return STATUS_INTERNAL_ERROR; }
- if (!params->ctx) + if (!params->cert_blob) { params->c->credentials = creds; return STATUS_SUCCESS; }
- if (!(crt = get_x509_crt(params->ctx))) + if (!(crt = get_x509_crt(params))) { pgnutls_certificate_free_credentials(creds); return STATUS_INTERNAL_ERROR; }
- if (!(key = get_x509_key(params->key_blob))) + if (!(key = get_x509_key(params->key_size, params->key_blob))) { pgnutls_x509_crt_deinit(crt); pgnutls_certificate_free_credentials(creds); diff --git a/dlls/secur32/secur32_priv.h b/dlls/secur32/secur32_priv.h index 814d9faf82a..e4fa0381433 100644 --- a/dlls/secur32/secur32_priv.h +++ b/dlls/secur32/secur32_priv.h @@ -115,8 +115,11 @@ struct session_params struct allocate_certificate_credentials_params { schan_credentials *c; - const CERT_CONTEXT *ctx; - const DATA_BLOB *key_blob; + ULONG cert_encoding; + ULONG cert_size; + BYTE *cert_blob; + ULONG key_size; + BYTE *key_blob; };
struct create_session_params
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel.c | 1 + dlls/secur32/schannel_gnutls.c | 23 +++++++++++++---------- dlls/secur32/secur32_priv.h | 1 + 3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 5d6e8763095..0973b3c2399 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -821,6 +821,7 @@ static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW(
create_params.transport = &ctx->transport; create_params.cred = cred; + create_params.session = &ctx->transport.session; if (GNUTLS_CALL( create_session, &create_params )) { schan_free_handle(handle, SCHAN_HANDLE_CTX); diff --git a/dlls/secur32/schannel_gnutls.c b/dlls/secur32/schannel_gnutls.c index 131b40a45d3..2e462b409d8 100644 --- a/dlls/secur32/schannel_gnutls.c +++ b/dlls/secur32/schannel_gnutls.c @@ -480,18 +480,20 @@ static NTSTATUS schan_create_session( void *args ) { const struct create_session_params *params = args; schan_credentials *cred = params->cred; - gnutls_session_t *s = (gnutls_session_t*)¶ms->transport->session; char priority[128] = "NORMAL:%LATEST_RECORD_VERSION", *p; BOOL using_vers_all = FALSE, disabled; unsigned int i, flags = (cred->credential_use == SECPKG_CRED_INBOUND) ? GNUTLS_SERVER : GNUTLS_CLIENT; + gnutls_session_t s; int err;
+ *params->session = 0; + if (cred->enabled_protocols & (SP_PROT_DTLS1_0_CLIENT | SP_PROT_DTLS1_2_CLIENT)) { flags |= GNUTLS_DATAGRAM | GNUTLS_NONBLOCK; }
- err = pgnutls_init(s, flags); + err = pgnutls_init(&s, flags); if (err != GNUTLS_E_SUCCESS) { pgnutls_perror(err); @@ -524,27 +526,28 @@ static NTSTATUS schan_create_session( void *args ) }
TRACE("Using %s priority\n", debugstr_a(priority)); - err = pgnutls_priority_set_direct(*s, priority, NULL); + err = pgnutls_priority_set_direct(s, priority, NULL); if (err != GNUTLS_E_SUCCESS) { pgnutls_perror(err); - pgnutls_deinit(*s); + pgnutls_deinit(s); return STATUS_INTERNAL_ERROR; }
- err = pgnutls_credentials_set(*s, GNUTLS_CRD_CERTIFICATE, + err = pgnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, (gnutls_certificate_credentials_t)cred->credentials); if (err != GNUTLS_E_SUCCESS) { pgnutls_perror(err); - pgnutls_deinit(*s); + pgnutls_deinit(s); return STATUS_INTERNAL_ERROR; }
- pgnutls_transport_set_pull_function(*s, pull_adapter); - if (flags & GNUTLS_DATAGRAM) pgnutls_transport_set_pull_timeout_function(*s, pull_timeout); - pgnutls_transport_set_push_function(*s, push_adapter); - pgnutls_transport_set_ptr(*s, (gnutls_transport_ptr_t)params->transport); + pgnutls_transport_set_pull_function(s, pull_adapter); + if (flags & GNUTLS_DATAGRAM) pgnutls_transport_set_pull_timeout_function(s, pull_timeout); + pgnutls_transport_set_push_function(s, push_adapter); + pgnutls_transport_set_ptr(s, (gnutls_transport_ptr_t)params->transport); + *params->session = (ULONG_PTR)s;
return STATUS_SUCCESS; } diff --git a/dlls/secur32/secur32_priv.h b/dlls/secur32/secur32_priv.h index e4fa0381433..e58303a4e1b 100644 --- a/dlls/secur32/secur32_priv.h +++ b/dlls/secur32/secur32_priv.h @@ -126,6 +126,7 @@ struct create_session_params { struct schan_transport *transport; schan_credentials *cred; + schan_session *session; };
struct free_certificate_credentials_params
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 0973b3c2399..618982d889e 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -444,40 +444,38 @@ static WCHAR *get_key_container_path(const CERT_CONTEXT *ctx) { char *str; if (!CryptGetProvParam(keyctx.hCryptProv, PP_CONTAINER, NULL, &size, 0)) return NULL; - if (!(str = RtlAllocateHeap(GetProcessHeap(), 0, size))) return NULL; + if (!(str = malloc(size))) return NULL; if (!CryptGetProvParam(keyctx.hCryptProv, PP_CONTAINER, (BYTE *)str, &size, 0)) return NULL;
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); - if (!(ret = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(L"Software\Wine\Crypto\RSA\") + len * sizeof(WCHAR)))) + if (!(ret = malloc(sizeof(L"Software\Wine\Crypto\RSA\") + len * sizeof(WCHAR)))) { - RtlFreeHeap(GetProcessHeap(), 0, str); + free(str); return NULL; } wcscpy(ret, L"Software\Wine\Crypto\RSA\"); MultiByteToWideChar(CP_ACP, 0, str, -1, ret + wcslen(ret), len); - RtlFreeHeap(GetProcessHeap(), 0, str); + free(str); } else if (CertGetCertificateContextProperty(ctx, CERT_KEY_PROV_INFO_PROP_ID, NULL, &prov_size)) { - if (!(prov = RtlAllocateHeap(GetProcessHeap(), 0, prov_size))) return NULL; + if (!(prov = malloc(prov_size))) return NULL; if (!CertGetCertificateContextProperty(ctx, CERT_KEY_PROV_INFO_PROP_ID, prov, &prov_size)) { - RtlFreeHeap(GetProcessHeap(), 0, prov); + free(prov); return NULL; } - if (!(ret = RtlAllocateHeap(GetProcessHeap(), 0, - sizeof(L"Software\Wine\Crypto\RSA\") + wcslen(prov->pwszContainerName) * sizeof(WCHAR)))) + if (!(ret = malloc(sizeof(L"Software\Wine\Crypto\RSA\") + wcslen(prov->pwszContainerName) * sizeof(WCHAR)))) { - RtlFreeHeap(GetProcessHeap(), 0, prov); + free(prov); return NULL; } wcscpy(ret, L"Software\Wine\Crypto\RSA\"); wcscat(ret, prov->pwszContainerName); - RtlFreeHeap(GetProcessHeap(), 0, prov); + free(prov); }
- if (!ret && GetUserNameW(username, &len) && - (ret = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(L"Software\Wine\Crypto\RSA\") + len * sizeof(WCHAR)))) + if (!ret && GetUserNameW(username, &len) && (ret = malloc(sizeof(L"Software\Wine\Crypto\RSA\") + len * sizeof(WCHAR)))) { wcscpy(ret, L"Software\Wine\Crypto\RSA\"); wcscat(ret, username); @@ -492,16 +490,15 @@ static BYTE *get_key_blob(const CERT_CONTEXT *ctx, DWORD *size) BYTE *buf, *ret = NULL; DATA_BLOB blob_in, blob_out; DWORD spec = 0, type, len; + LSTATUS retval; WCHAR *path; HKEY hkey;
if (!(path = get_key_container_path(ctx))) return NULL; - if (RegOpenKeyExW(HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey)) - { - RtlFreeHeap(GetProcessHeap(), 0, path); + retval = RegOpenKeyExW(HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey); + free(path); + if (retval) return NULL; - } - RtlFreeHeap(GetProcessHeap(), 0, path);
if (!RegQueryValueExW(hkey, L"KeyExchangeKeyPair", 0, &type, NULL, &len)) spec = AT_KEYEXCHANGE; else if (!RegQueryValueExW(hkey, L"SignatureKeyPair", 0, &type, NULL, &len)) spec = AT_SIGNATURE; @@ -511,7 +508,7 @@ static BYTE *get_key_blob(const CERT_CONTEXT *ctx, DWORD *size) return NULL; }
- if (!(buf = RtlAllocateHeap(GetProcessHeap(), 0, len + MAX_LEAD_BYTES))) + if (!(buf = malloc(len + MAX_LEAD_BYTES))) { RegCloseKey(hkey); return NULL; @@ -531,7 +528,7 @@ static BYTE *get_key_blob(const CERT_CONTEXT *ctx, DWORD *size) ret = buf; } } - else RtlFreeHeap(GetProcessHeap(), 0, buf); + else free(buf);
RegCloseKey(hkey); return ret; @@ -593,7 +590,7 @@ static SECURITY_STATUS schan_AcquireClientCredentials(const void *schanCred, params.key_size = key_size; params.key_blob = key_blob; if (GNUTLS_CALL( allocate_certificate_credentials, ¶ms )) goto fail; - RtlFreeHeap(GetProcessHeap(), 0, key_blob); + free(key_blob);
handle = schan_alloc_handle(creds, SCHAN_HANDLE_CRED); if (handle == SCHAN_INVALID_HANDLE) goto fail; @@ -612,7 +609,7 @@ static SECURITY_STATUS schan_AcquireClientCredentials(const void *schanCred,
fail: free(creds); - RtlFreeHeap(GetProcessHeap(), 0, key_blob); + free(key_blob); return SEC_E_INTERNAL_ERROR; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/secur32/schannel.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 618982d889e..30c86c724b4 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -806,9 +806,8 @@ static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW( return SEC_E_INVALID_HANDLE; }
- if (!(ctx = malloc(sizeof(*ctx)))) return SEC_E_INSUFFICIENT_MEMORY; + if (!(ctx = calloc(1, sizeof(*ctx)))) return SEC_E_INSUFFICIENT_MEMORY;
- ctx->cert = NULL; handle = schan_alloc_handle(ctx, SCHAN_HANDLE_CTX); if (handle == SCHAN_INVALID_HANDLE) {