From 0eab70f80660ec6f6fb7bc2aeb012f1ac7a12e28 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 1 Nov 2023 14:10:49 +1000 Subject: [PATCH] Regression test fixes Fixes for different configurations and memory allocation failure testing. --- src/crl.c | 1 + src/dtls13.c | 4 +++- src/ssl.c | 3 +++ tests/api.c | 15 ++++++++++----- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/crl.c b/src/crl.c index 2fc5341fc..dbe5a2d0a 100644 --- a/src/crl.c +++ b/src/crl.c @@ -628,6 +628,7 @@ int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type, ret = AddCRL(crl, dcrl, myBuffer, ret != ASN_CRL_NO_SIGNER_E); if (ret != 0) { WOLFSSL_MSG("AddCRL error"); + crl->currentEntry = NULL; } } diff --git a/src/dtls13.c b/src/dtls13.c index 2a2e543cd..6efc7bb46 100644 --- a/src/dtls13.c +++ b/src/dtls13.c @@ -943,8 +943,10 @@ static int Dtls13SendFragmentedInternal(WOLFSSL* ssl) } ret = CheckAvailableSize(ssl, recordLength + MAX_MSG_EXTRA); - if (ret != 0) + if (ret != 0) { + Dtls13FreeFragmentsBuffer(ssl); return ret; + } output = GetOutputBuffer(ssl); diff --git a/src/ssl.c b/src/ssl.c index b390efd63..3089225d1 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -35991,6 +35991,9 @@ PKCS7* wolfSSL_d2i_PKCS7_ex(PKCS7** p7, const unsigned char** in, int len, != 0) { WOLFSSL_MSG("wc_PKCS7_VerifySignedData failed"); wolfSSL_PKCS7_free((PKCS7*)pkcs7); + if (p7 != NULL) { + *p7 = NULL; + } return NULL; } } diff --git a/tests/api.c b/tests/api.c index cac34e717..8f1457223 100644 --- a/tests/api.c +++ b/tests/api.c @@ -1859,7 +1859,9 @@ static int test_wolfSSL_CertManagerAPI(void) #if !defined(NO_FILESYSTEM) { const char* ca_cert = "./certs/ca-cert.pem"; + #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) const char* ca_cert_der = "./certs/ca-cert.der"; + #endif const char* ca_path = "./certs"; #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH) @@ -41784,8 +41786,10 @@ static int test_wolfSSL_BIO_gets(void) ExpectNotNull(emp_bm = BUF_MEM_new()); ExpectNotNull(msg_bm = BUF_MEM_new()); ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg)); - if (EXPECT_SUCCESS()) + if (EXPECT_SUCCESS()) { XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL); + msg_bm->data = NULL; + } /* emp size is 1 for terminator */ ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp)); if (EXPECT_SUCCESS()) { @@ -43618,6 +43622,7 @@ static int test_wolfSSL_GENERAL_NAME_print(void) ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0); sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free); + gn = NULL; sk = NULL; X509_free(x509); x509 = NULL; @@ -59052,12 +59057,12 @@ static int test_openssl_generate_key_and_cert(void) { EXPECT_DECLS; #if defined(OPENSSL_EXTRA) + int expectedDerSz; EVP_PKEY* pkey = NULL; #ifdef HAVE_ECC EC_KEY* ec_key = NULL; #endif #if !defined(NO_RSA) - int expectedDerSz; int key_length = 2048; BIGNUM* exponent = NULL; RSA* rsa = NULL; @@ -59102,7 +59107,6 @@ static int test_openssl_generate_key_and_cert(void) #endif } - (void)expectedDerSz; EVP_PKEY_free(pkey); pkey = NULL; BN_free(exponent); @@ -59132,6 +59136,7 @@ static int test_openssl_generate_key_and_cert(void) EVP_PKEY_free(pkey); #endif /* HAVE_ECC */ (void)pkey; + (void)expectedDerSz; #endif /* OPENSSL_EXTRA */ return EXPECT_RESULT(); @@ -59265,10 +59270,10 @@ static int test_wolfSSL_CTX_LoadCRL(void) #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \ WOLFSSL_SUCCESS) #ifndef NO_WOLFSSL_CLIENT - #define NEW_CTX(ctx) AssertNotNull( \ + #define NEW_CTX(ctx) ExpectNotNull( \ (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method())) #elif !defined(NO_WOLFSSL_SERVER) - #define NEW_CTX(ctx) AssertNotNull( \ + #define NEW_CTX(ctx) ExpectNotNull( \ (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method())) #else #define NEW_CTX(ctx) return