Skip to content

Commit 65d7c6a

Browse files
committed
Do not overwrite cert in wolfSSL_set_SSL_CTX if one is already set, remove unreachable frees.
1 parent dcf3af5 commit 65d7c6a

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

src/internal.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6806,9 +6806,6 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
68066806
#ifdef WOLFSSL_COPY_CERT
68076807
/* If WOLFSSL_COPY_CERT is defined, always copy the cert */
68086808
if (ctx->certificate != NULL) {
6809-
if (ssl->buffers.certificate != NULL) {
6810-
FreeDer(&ssl->buffers.certificate);
6811-
}
68126809
ret = AllocCopyDer(&ssl->buffers.certificate, ctx->certificate->buffer,
68136810
ctx->certificate->length, ctx->certificate->type,
68146811
ctx->certificate->heap);
@@ -6820,9 +6817,6 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
68206817
ret = WOLFSSL_SUCCESS;
68216818
}
68226819
if (ctx->certChain != NULL) {
6823-
if (ssl->buffers.certChain != NULL) {
6824-
FreeDer(&ssl->buffers.certChain);
6825-
}
68266820
ret = AllocCopyDer(&ssl->buffers.certChain, ctx->certChain->buffer,
68276821
ctx->certChain->length, ctx->certChain->type,
68286822
ctx->certChain->heap);

src/ssl.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20152,11 +20152,10 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2015220152

2015320153
#ifndef NO_CERTS
2015420154
#ifdef WOLFSSL_COPY_CERT
20155-
/* If WOLFSSL_COPY_CERT defined, always make new copy of cert */
20156-
if (ctx->certificate != NULL) {
20157-
if (ssl->buffers.certificate != NULL) {
20158-
FreeDer(&ssl->buffers.certificate);
20159-
}
20155+
/* If WOLFSSL_COPY_CERT defined, make new copy of cert from ctx
20156+
* unless SSL object already has a cert */
20157+
if ((ctx->certificate != NULL) &&
20158+
(ssl->buffers.certificate == NULL)) {
2016020159
ret = AllocCopyDer(&ssl->buffers.certificate, ctx->certificate->buffer,
2016120160
ctx->certificate->length, ctx->certificate->type,
2016220161
ctx->certificate->heap);
@@ -20167,10 +20166,8 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2016720166
ssl->buffers.weOwnCert = 1;
2016820167
ret = WOLFSSL_SUCCESS;
2016920168
}
20170-
if (ctx->certChain != NULL) {
20171-
if (ssl->buffers.certChain != NULL) {
20172-
FreeDer(&ssl->buffers.certChain);
20173-
}
20169+
if ((ctx->certChain != NULL) &&
20170+
(ssl->buffers.certChain == NULL)) {
2017420171
ret = AllocCopyDer(&ssl->buffers.certChain, ctx->certChain->buffer,
2017520172
ctx->certChain->length, ctx->certChain->type,
2017620173
ctx->certChain->heap);

0 commit comments

Comments
 (0)