Add a test case for EVP_MD_meth_dup() and EVP_CIPHER_meth_dup()
authorMatt Caswell <matt@openssl.org>
Tue, 27 Jul 2021 09:32:49 +0000 (10:32 +0100)
committerPauli <pauli@openssl.org>
Tue, 27 Jul 2021 23:37:09 +0000 (09:37 +1000)
Check that EVP_MD_meth_free() and EVP_CIPHER_meth_free() does actually
free the data.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16159)

test/evp_extra_test.c

index 7494c1f21b59aa0710f66e4a97d38322c53e3c08..e03e2a252e9f3f32fa3d9cbdb6b49bce036d2a49 100644 (file)
@@ -3690,7 +3690,25 @@ static int test_custom_pmeth(int idx)
     custom_pmeth = NULL;
     return testresult;
 }
-#endif
+
+static int test_evp_md_cipher_meth(void)
+{
+    EVP_MD *md = EVP_MD_meth_dup(EVP_sha256());
+    EVP_CIPHER *ciph = EVP_CIPHER_meth_dup(EVP_aes_128_cbc());
+    int testresult = 0;
+
+    if (!TEST_ptr(md) || !TEST_ptr(ciph))
+        goto err;
+
+    testresult = 1;
+
+ err:
+    EVP_MD_meth_free(md);
+    EVP_CIPHER_meth_free(ciph);
+
+    return testresult;
+}
+#endif /* OPENSSL_NO_DEPRECATED_3_0 */
 
 typedef enum OPTION_choice {
     OPT_ERR = -1,
@@ -3814,6 +3832,7 @@ int setup_tests(void)
 
 #ifndef OPENSSL_NO_DEPRECATED_3_0
     ADD_ALL_TESTS(test_custom_pmeth, 12);
+    ADD_TEST(test_evp_md_cipher_meth);
 #endif
 
     return 1;