]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/ml_kem_internal_test.c: Add EVP_MD_free() in the error path to avoid memory...
authorJiasheng Jiang <jiashengjiangcool@gmail.com>
Mon, 11 Aug 2025 21:52:59 +0000 (21:52 +0000)
committerPauli <ppzgs1@gmail.com>
Fri, 15 Aug 2025 01:01:51 +0000 (11:01 +1000)
Add EVP_MD_free() to free sha256 in the error path to avoid memory leak.

Fixes: d2136d9 ("Multi-variant ML-KEM")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27946)

test/ml_kem_internal_test.c

index bb745a2afc1ac3288e84b713c65472ab97674c22..c8c4cdf6f4d039a6ddba3ebbac06b6f0ffcee623 100644 (file)
@@ -107,8 +107,10 @@ static int sanity_test(void)
         return 0;
 
     if (!TEST_ptr(privctx = RAND_get0_private(NULL))
-        || !TEST_ptr(pubctx = RAND_get0_public(NULL)))
-        return 0;
+        || !TEST_ptr(pubctx = RAND_get0_public(NULL))) {
+        ret = -1;
+        goto err;
+    }
 
     decap_entropy = ml_kem_public_entropy + ML_KEM_RANDOM_BYTES;
 
@@ -134,8 +136,10 @@ static int sanity_test(void)
         params[1] =
             OSSL_PARAM_construct_uint(OSSL_RAND_PARAM_STRENGTH, &strength);
         params[2] = OSSL_PARAM_construct_end();
-        if (!TEST_true(EVP_RAND_CTX_set_params(privctx, params)))
-            return 0;
+        if (!TEST_true(EVP_RAND_CTX_set_params(privctx, params))) {
+            ret = -1;
+            goto err;
+        }
 
         public_key = ossl_ml_kem_key_new(NULL, NULL, alg[i]);
         private_key = ossl_ml_kem_key_new(NULL, NULL, alg[i]);
@@ -254,6 +258,8 @@ static int sanity_test(void)
         OPENSSL_free(encoded_public_key);
         OPENSSL_free(ciphertext);
     }
+
+err:
     EVP_MD_free(sha256);
     return ret == 0;
 }