Skip to content

Commit

Permalink
Fix double free of ossock->ossl_ctx in case of errors (#3069) (#3070)
Browse files Browse the repository at this point in the history
  • Loading branch information
johado committed Apr 18, 2022
1 parent d653375 commit 863629b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pjlib/src/pj/ssl_sock_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ static pj_status_t init_ossl_ctx(pj_ssl_sock_t *ssock)
cert->CA_path.ptr));
}
SSL_CTX_free(ctx);
ossock->ossl_ctx = NULL;
return status;
} else {
PJ_LOG(4,(ssock->pool->obj_name,
Expand Down Expand Up @@ -1204,6 +1205,7 @@ static pj_status_t init_ossl_ctx(pj_ssl_sock_t *ssock)
"Error loading certificate chain file '%s'",
cert->cert_file.ptr));
SSL_CTX_free(ctx);
ossock->ossl_ctx = NULL;
return status;
} else {
PJ_LOG(4,(ssock->pool->obj_name,
Expand All @@ -1225,6 +1227,7 @@ static pj_status_t init_ossl_ctx(pj_ssl_sock_t *ssock)
"Error adding private key from '%s'",
cert->privkey_file.ptr));
SSL_CTX_free(ctx);
ossock->ossl_ctx = NULL;
return status;
} else {
PJ_LOG(4,(ssock->pool->obj_name,
Expand Down Expand Up @@ -1274,6 +1277,7 @@ static pj_status_t init_ossl_ctx(pj_ssl_sock_t *ssock)
X509_free(xcert);
BIO_free(cbio);
SSL_CTX_free(ctx);
ossock->ossl_ctx = NULL;
return status;
} else {
PJ_LOG(4,(ssock->pool->obj_name,
Expand Down Expand Up @@ -1342,6 +1346,7 @@ static pj_status_t init_ossl_ctx(pj_ssl_sock_t *ssock)
EVP_PKEY_free(pkey);
BIO_free(kbio);
SSL_CTX_free(ctx);
ossock->ossl_ctx = NULL;
return status;
} else {
PJ_LOG(4,(ssock->pool->obj_name,
Expand Down

0 comments on commit 863629b

Please sign in to comment.