]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
check for null returns in test_base64_simdutf.c
authorNeil Horman <nhorman@openssl.org>
Tue, 30 Dec 2025 17:19:05 +0000 (12:19 -0500)
committerNeil Horman <nhorman@openssl.org>
Sun, 4 Jan 2026 22:51:49 +0000 (17:51 -0500)
We derferences two pointers in this code which we fail to check for null
first.  reported by:

https://scan5.scan.coverity.com/#/project-view/60762/10222?selectedIssue=1677832

Just move the null check a bit higher

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29525)

test/test_base64_simdutf.c

index a39155dc44fed81e5be6dd1fb285c04e29c3538e..74cbab240a0c0d0d8339eca929e7b41e39bdc02e 100644 (file)
@@ -184,6 +184,13 @@ static int test_encode_line_lengths_reinforced(void)
                 EVP_ENCODE_CTX *ctx_simd = EVP_ENCODE_CTX_new();
                 EVP_ENCODE_CTX *ctx_ref = EVP_ENCODE_CTX_new();
 
+                if (!ctx_simd || !ctx_ref) {
+                    EVP_ENCODE_CTX_free(ctx_simd);
+                    EVP_ENCODE_CTX_free(ctx_ref);
+                    TEST_error("Out of memory for contexts");
+                    return 0;
+                }
+
                 fuzz_fill_encode_ctx(ctx_simd, partial_ctx_fill);
 
                 memset(out_simd, 0xCC, sizeof(out_simd)); /* poison to catch short writes */
@@ -192,13 +199,6 @@ static int test_encode_line_lengths_reinforced(void)
                 int outlen_simd = 0, outlen_ref = 0; /* bytes produced by Update */
                 int finlen_simd = 0, finlen_ref = 0; /* bytes produced by Final */
 
-                if (!ctx_simd || !ctx_ref) {
-                    EVP_ENCODE_CTX_free(ctx_simd);
-                    EVP_ENCODE_CTX_free(ctx_ref);
-                    TEST_error("Out of memory for contexts");
-                    return 0;
-                }
-
                 EVP_EncodeInit(ctx_simd);
                 EVP_EncodeInit(ctx_ref);
                 ctx_simd->length = ctx_len;