@@ -19793,11 +19793,15 @@ void wolfSSL_certs_clear(WOLFSSL* ssl)
1979319793 return;
1979419794
1979519795 /* ctx still owns certificate, certChain, key, dh, and cm */
19796- if (ssl->buffers.weOwnCert)
19796+ if (ssl->buffers.weOwnCert) {
1979719797 FreeDer(&ssl->buffers.certificate);
19798+ ssl->buffers.weOwnCert = 0;
19799+ }
1979819800 ssl->buffers.certificate = NULL;
19799- if (ssl->buffers.weOwnCertChain)
19801+ if (ssl->buffers.weOwnCertChain) {
1980019802 FreeDer(&ssl->buffers.certChain);
19803+ ssl->buffers.weOwnCertChain = 0;
19804+ }
1980119805 ssl->buffers.certChain = NULL;
1980219806#ifdef WOLFSSL_TLS13
1980319807 ssl->buffers.certChainCnt = 0;
@@ -19807,6 +19811,7 @@ void wolfSSL_certs_clear(WOLFSSL* ssl)
1980719811 #ifdef WOLFSSL_BLIND_PRIVATE_KEY
1980819812 FreeDer(&ssl->buffers.keyMask);
1980919813 #endif
19814+ ssl->buffers.weOwnKey = 0;
1981019815 }
1981119816 ssl->buffers.key = NULL;
1981219817#ifdef WOLFSSL_BLIND_PRIVATE_KEY
@@ -19823,6 +19828,7 @@ void wolfSSL_certs_clear(WOLFSSL* ssl)
1982319828 #ifdef WOLFSSL_BLIND_PRIVATE_KEY
1982419829 FreeDer(&ssl->buffers.altKeyMask);
1982519830 #endif
19831+ ssl->buffers.weOwnAltKey = 0;
1982619832 }
1982719833 ssl->buffers.altKey = NULL;
1982819834#ifdef WOLFSSL_BLIND_PRIVATE_KEY
@@ -20402,11 +20408,13 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2040220408 if (ctx->certificate != NULL) {
2040320409 if (ssl->buffers.certificate != NULL) {
2040420410 FreeDer(&ssl->buffers.certificate);
20411+ ssl->buffers.certificate = NULL;
2040520412 }
2040620413 ret = AllocCopyDer(&ssl->buffers.certificate, ctx->certificate->buffer,
2040720414 ctx->certificate->length, ctx->certificate->type,
2040820415 ctx->certificate->heap);
2040920416 if (ret != 0) {
20417+ ssl->buffers.weOwnCert = 0;
2041020418 return NULL;
2041120419 }
2041220420
@@ -20416,11 +20424,13 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2041620424 if (ctx->certChain != NULL) {
2041720425 if (ssl->buffers.certChain != NULL) {
2041820426 FreeDer(&ssl->buffers.certChain);
20427+ ssl->buffers.certChain = NULL;
2041920428 }
2042020429 ret = AllocCopyDer(&ssl->buffers.certChain, ctx->certChain->buffer,
2042120430 ctx->certChain->length, ctx->certChain->type,
2042220431 ctx->certChain->heap);
2042320432 if (ret != 0) {
20433+ ssl->buffers.weOwnCertChain = 0;
2042420434 return NULL;
2042520435 }
2042620436
@@ -20440,10 +20450,15 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2044020450 if (ctx->privateKey != NULL) {
2044120451 if (ssl->buffers.key != NULL) {
2044220452 FreeDer(&ssl->buffers.key);
20453+ ssl->buffers.key = NULL;
2044320454 }
20444- AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
20455+ ret = AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
2044520456 ctx->privateKey->length, ctx->privateKey->type,
2044620457 ctx->privateKey->heap);
20458+ if (ret != 0) {
20459+ ssl->buffers.weOwnKey = 0;
20460+ return NULL;
20461+ }
2044720462 ssl->buffers.weOwnKey = 1;
2044820463 }
2044920464 else {
@@ -20454,15 +20469,18 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2045420469#endif
2045520470#else
2045620471 if (ctx->privateKey != NULL) {
20457- AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
20472+ ret = AllocCopyDer(&ssl->buffers.key, ctx->privateKey->buffer,
2045820473 ctx->privateKey->length, ctx->privateKey->type,
2045920474 ctx->privateKey->heap);
20475+ if (ret != 0) {
20476+ return NULL;
20477+ }
2046020478 /* Blind the private key for the SSL with new random mask. */
2046120479 wolfssl_priv_der_unblind(ssl->buffers.key, ctx->privateKeyMask);
2046220480 ret = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.key,
2046320481 &ssl->buffers.keyMask);
2046420482 if (ret != 0) {
20465- return ret ;
20483+ return NULL ;
2046620484 }
2046720485 }
2046820486#endif
@@ -20484,15 +20502,18 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2048420502 ssl->buffers.altKey = ctx->altPrivateKey;
2048520503#else
2048620504 if (ctx->altPrivateKey != NULL) {
20487- AllocCopyDer(&ssl->buffers.altkey, ctx->altPrivateKey->buffer,
20505+ ret = AllocCopyDer(&ssl->buffers.altkey, ctx->altPrivateKey->buffer,
2048820506 ctx->altPrivateKey->length, ctx->altPrivateKey->type,
2048920507 ctx->altPrivateKey->heap);
20508+ if (ret != 0) {
20509+ return NULL;
20510+ }
2049020511 /* Blind the private key for the SSL with new random mask. */
2049120512 wolfssl_priv_der_unblind(ssl->buffers.altKey, ctx->altPrivateKeyMask);
2049220513 ret = wolfssl_priv_der_blind(ssl->rng, ssl->buffers.altKey,
2049320514 &ssl->buffers.altKeyMask);
2049420515 if (ret != 0) {
20495- return ret ;
20516+ return NULL ;
2049620517 }
2049720518 }
2049820519#endif
0 commit comments