testutil: Make SETUP_TEST_FIXTURE return 0 on fixture == NULL Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/11808)
diff --git a/test/cipherlist_test.c b/test/cipherlist_test.c index f850d7b..0f337b4 100644 --- a/test/cipherlist_test.c +++ b/test/cipherlist_test.c
@@ -199,8 +199,6 @@ static int test_default_cipherlist_implicit(void) { SETUP_CIPHERLIST_TEST_FIXTURE(); - if (fixture == NULL) - return 0; EXECUTE_CIPHERLIST_TEST(); return result; } @@ -208,8 +206,6 @@ static int test_default_cipherlist_explicit(void) { SETUP_CIPHERLIST_TEST_FIXTURE(); - if (fixture == NULL) - return 0; if (!TEST_true(SSL_CTX_set_cipher_list(fixture->server, "DEFAULT")) || !TEST_true(SSL_CTX_set_cipher_list(fixture->client, "DEFAULT"))) tear_down(fixture); @@ -220,11 +216,8 @@ /* SSL_CTX_set_cipher_list() should fail if it clears all TLSv1.2 ciphers. */ static int test_default_cipherlist_clear(void) { - SETUP_CIPHERLIST_TEST_FIXTURE(); SSL *s = NULL; - - if (fixture == NULL) - return 0; + SETUP_CIPHERLIST_TEST_FIXTURE(); if (!TEST_int_eq(SSL_CTX_set_cipher_list(fixture->server, "no-such"), 0)) goto end;
diff --git a/test/cmp_hdr_test.c b/test/cmp_hdr_test.c index cd30c49..24299ab 100644 --- a/test/cmp_hdr_test.c +++ b/test/cmp_hdr_test.c
@@ -402,9 +402,10 @@ static int test_HDR_init_with_ref(void) { - SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); unsigned char ref[CMP_TEST_REFVALUE_LENGTH]; + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); + fixture->expected = 1; if (!TEST_int_eq(1, RAND_bytes(ref, sizeof(ref))) || !TEST_true(OSSL_CMP_CTX_set1_referenceValue(fixture->cmp_ctx, @@ -418,9 +419,9 @@ static int test_HDR_init_with_subject(void) { - SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); X509_NAME *subject = NULL; + SETUP_TEST_FIXTURE(CMP_HDR_TEST_FIXTURE, set_up); fixture->expected = 1; if (!TEST_ptr(subject = X509_NAME_new()) || !TEST_true(X509_NAME_ADD(subject, "CN", "Common Name"))
diff --git a/test/cmp_msg_test.c b/test/cmp_msg_test.c index 92989f9..ca2a651 100644 --- a/test/cmp_msg_test.c +++ b/test/cmp_msg_test.c
@@ -137,10 +137,12 @@ static int test_cmp_create_ir_protection_set(void) { - SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); - OSSL_CMP_CTX *ctx = fixture->cmp_ctx; + OSSL_CMP_CTX *ctx; unsigned char secret[16]; + SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); + + ctx = fixture->cmp_ctx; fixture->bodytype = OSSL_CMP_PKIBODY_IR; fixture->err_code = -1; fixture->expected = 1; @@ -213,10 +215,11 @@ static int test_cmp_create_p10cr(void) { - SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); - OSSL_CMP_CTX *ctx = fixture->cmp_ctx; + OSSL_CMP_CTX *ctx; X509_REQ *p10cr = NULL; + SETUP_TEST_FIXTURE(CMP_MSG_TEST_FIXTURE, set_up); + ctx = fixture->cmp_ctx; fixture->bodytype = OSSL_CMP_PKIBODY_P10CR; fixture->err_code = CMP_R_ERROR_CREATING_CERTREQ; fixture->expected = 1;
diff --git a/test/cmp_protect_test.c b/test/cmp_protect_test.c index 1d1e009..eed850e 100644 --- a/test/cmp_protect_test.c +++ b/test/cmp_protect_test.c
@@ -252,9 +252,10 @@ static int test_MSG_protect_certificate_based_without_cert(void) { - SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up); - OSSL_CMP_CTX *ctx = fixture->cmp_ctx; + OSSL_CMP_CTX *ctx; + SETUP_TEST_FIXTURE(CMP_PROTECT_TEST_FIXTURE, set_up); + ctx = fixture->cmp_ctx; fixture->expected = 0; if (!TEST_ptr(fixture->msg = OSSL_CMP_MSG_dup(ir_unprotected))
diff --git a/test/cmp_vfy_test.c b/test/cmp_vfy_test.c index fcecca2..4c705f6 100644 --- a/test/cmp_vfy_test.c +++ b/test/cmp_vfy_test.c
@@ -140,13 +140,14 @@ static int test_validate_msg_mac_alg_protection(void) { - SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up); /* secret value belonging to cmp-test/CMP_IP_waitingStatus_PBM.der */ const unsigned char sec_1[] = { '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3', 'Q', '-', 'u', 'd', 'N', 'R' }; + SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up); + fixture->expected = 1; if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_1, sizeof(sec_1))) @@ -161,11 +162,12 @@ #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION static int test_validate_msg_mac_alg_protection_bad(void) { - SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up); const unsigned char sec_bad[] = { '9', 'p', 'p', '8', '-', 'b', '3', '5', 'i', '-', 'X', 'd', '3', 'Q', '-', 'u', 'd', 'N', 'r' }; + + SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up); fixture->expected = 0; if (!TEST_true(OSSL_CMP_CTX_set1_secretValue(fixture->cmp_ctx, sec_bad, @@ -192,9 +194,11 @@ static int test_validate_msg_signature_partial_chain(int expired) { - SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up); - X509_STORE *ts = OSSL_CMP_CTX_get0_trustedStore(fixture->cmp_ctx); + X509_STORE *ts; + SETUP_TEST_FIXTURE(CMP_VFY_TEST_FIXTURE, set_up); + + ts = OSSL_CMP_CTX_get0_trustedStore(fixture->cmp_ctx); fixture->expected = !expired; if (ts == NULL || !TEST_ptr(fixture->msg = load_pkimsg(ir_protected_f))
diff --git a/test/ct_test.c b/test/ct_test.c index 79ffcbf..2e161a7 100644 --- a/test/ct_test.c +++ b/test/ct_test.c
@@ -338,8 +338,6 @@ static int test_no_scts_in_certificate(void) { SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->certs_dir = certs_dir; fixture->certificate_file = "leaf.pem"; fixture->issuer_file = "subinterCA.pem"; @@ -351,8 +349,6 @@ static int test_one_sct_in_certificate(void) { SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; @@ -366,8 +362,6 @@ static int test_multiple_scts_in_certificate(void) { SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; @@ -381,8 +375,6 @@ static int test_verify_one_sct(void) { SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; fixture->issuer_file = "embeddedSCTs1_issuer.pem"; @@ -395,8 +387,6 @@ static int test_verify_multiple_scts(void) { SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs3.pem"; fixture->issuer_file = "embeddedSCTs3_issuer.pem"; @@ -409,8 +399,6 @@ static int test_verify_fails_for_future_sct(void) { SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->epoch_time_in_ms = 1365094800000ULL; /* Apr 4 17:00:00 2013 GMT */ fixture->certs_dir = certs_dir; fixture->certificate_file = "embeddedSCTs1.pem"; @@ -443,8 +431,6 @@ "\xED\xBF\x08"; SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->tls_sct_list = tls_sct_list; fixture->tls_sct_list_len = 0x7a; fixture->sct_dir = ct_dir; @@ -463,8 +449,6 @@ SCT *sct = NULL; SETUP_CT_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->sct_list = sk_SCT_new_null(); if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id,
diff --git a/test/ssl_test_ctx_test.c b/test/ssl_test_ctx_test.c index 16ce32a..91f4180 100644 --- a/test/ssl_test_ctx_test.c +++ b/test/ssl_test_ctx_test.c
@@ -151,8 +151,6 @@ static int test_empty_configuration(void) { SETUP_SSL_TEST_CTX_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->test_section = "ssltest_default"; fixture->expected_ctx->expected_result = SSL_TEST_SUCCESS; EXECUTE_SSL_TEST_CTX_TEST(); @@ -162,8 +160,6 @@ static int test_good_configuration(void) { SETUP_SSL_TEST_CTX_TEST_FIXTURE(); - if (fixture == NULL) - return 0; fixture->test_section = "ssltest_good"; fixture->expected_ctx->method = SSL_TEST_METHOD_DTLS; fixture->expected_ctx->handshake_mode = SSL_TEST_HANDSHAKE_RESUME;
diff --git a/test/testutil.h b/test/testutil.h index 88a3cbc..c5c284a 100644 --- a/test/testutil.h +++ b/test/testutil.h
@@ -67,6 +67,7 @@ * object called "fixture". It will also allocate the "result" variable used * by EXECUTE_TEST. set_up() should take a const char* specifying the test * case name and return a TEST_FIXTURE_TYPE by reference. + * If case set_up() fails then 0 is returned. * * EXECUTE_TEST will pass fixture to execute_func() by reference, call * tear_down(), and return the result of execute_func(). execute_func() should @@ -94,7 +95,11 @@ */ # define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\ TEST_FIXTURE_TYPE *fixture = set_up(TEST_CASE_NAME); \ - int result = 0 + int result = 0; \ +\ + if (fixture == NULL) \ + return 0 + # define EXECUTE_TEST(execute_func, tear_down)\ if (fixture != NULL) {\