Skip to content

Commit 2edd18c

Browse files
committed
src/x509.c: fix nullPointerRedundantCheck in wolfSSL_X509V3_set_ctx(). also adds thorough WOLFSSL_MSG() coverage for failures.
1 parent d043333 commit 2edd18c

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

src/x509.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13848,35 +13848,50 @@ void wolfSSL_X509V3_set_ctx(WOLFSSL_X509V3_CTX* ctx, WOLFSSL_X509* issuer,
1384813848
{
1384913849
int ret = WOLFSSL_SUCCESS;
1385013850
WOLFSSL_ENTER("wolfSSL_X509V3_set_ctx");
13851-
if (!ctx)
13852-
return;
13851+
if (!ctx) {
13852+
ret = WOLFSSL_FAILURE;
13853+
WOLFSSL_MSG("wolfSSL_X509V3_set_ctx() called with null ctx.");
13854+
}
1385313855

13854-
/* not checking ctx->x509 for null first since app won't have initialized
13855-
* this X509V3_CTX before this function call */
13856-
ctx->x509 = wolfSSL_X509_new_ex(issuer->heap);
13857-
if (!ctx->x509)
13858-
return;
13856+
if (ret == WOLFSSL_SUCCESS && (ctx->x509 != NULL)) {
13857+
ret = WOLFSSL_FAILURE;
13858+
WOLFSSL_MSG("wolfSSL_X509V3_set_ctx() called "
13859+
"with ctx->x509 already allocated.");
13860+
}
13861+
13862+
if (ret == WOLFSSL_SUCCESS) {
13863+
ctx->x509 = wolfSSL_X509_new_ex(
13864+
(issuer && issuer->heap) ? issuer->heap :
13865+
(subject && subject->heap) ? subject->heap :
13866+
(req && req->heap) ? req->heap :
13867+
NULL);
13868+
if (!ctx->x509) {
13869+
ret = WOLFSSL_FAILURE;
13870+
WOLFSSL_MSG("wolfSSL_X509_new_ex() failed "
13871+
"in wolfSSL_X509V3_set_ctx().");
13872+
}
13873+
}
1385913874

1386013875
/* Set parameters in ctx as long as ret == WOLFSSL_SUCCESS */
13861-
if (issuer)
13876+
if (ret == WOLFSSL_SUCCESS && issuer)
1386213877
ret = wolfSSL_X509_set_issuer_name(ctx->x509,&issuer->issuer);
1386313878

13864-
if (subject && ret == WOLFSSL_SUCCESS)
13879+
if (ret == WOLFSSL_SUCCESS && subject)
1386513880
ret = wolfSSL_X509_set_subject_name(ctx->x509,&subject->subject);
1386613881

13867-
if (req && ret == WOLFSSL_SUCCESS) {
13882+
if (ret == WOLFSSL_SUCCESS && req) {
1386813883
WOLFSSL_MSG("req not implemented.");
1386913884
}
1387013885

13871-
if (crl && ret == WOLFSSL_SUCCESS) {
13886+
if (ret == WOLFSSL_SUCCESS && crl) {
1387213887
WOLFSSL_MSG("crl not implemented.");
1387313888
}
1387413889

13875-
if (flag && ret == WOLFSSL_SUCCESS) {
13890+
if (ret == WOLFSSL_SUCCESS && flag) {
1387613891
WOLFSSL_MSG("flag not implemented.");
1387713892
}
1387813893

13879-
if (!ret) {
13894+
if (ret != WOLFSSL_SUCCESS) {
1388013895
WOLFSSL_MSG("Error setting WOLFSSL_X509V3_CTX parameters.");
1388113896
}
1388213897
}

0 commit comments

Comments
 (0)