]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
EVP_MD_CTX_copy_ex: Allow copying uninitialized digest contexts
authorTomas Mraz <tomas@openssl.org>
Tue, 23 Nov 2021 14:52:04 +0000 (15:52 +0100)
committerTomas Mraz <tomas@openssl.org>
Wed, 24 Nov 2021 17:42:27 +0000 (18:42 +0100)
Fixes #17117

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17118)

crypto/evp/digest.c

index 0a133c5c15a59c74715509b01c474df14bd34612..7ebb2e323527a13c0a05e81268c95f3ba4317960 100644 (file)
@@ -510,11 +510,20 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
 {
     unsigned char *tmp_buf;
 
-    if (in == NULL || in->digest == NULL) {
-        ERR_raise(ERR_LIB_EVP, EVP_R_INPUT_NOT_INITIALIZED);
+    if (in == NULL) {
+        ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
         return 0;
     }
 
+    if (in->digest == NULL) {
+        /* copying uninitialized digest context */
+        EVP_MD_CTX_reset(out);
+        if (out->fetched_digest != NULL)
+            EVP_MD_free(out->fetched_digest);
+        *out = *in;
+        return 1;
+    }
+
     if (in->digest->prov == NULL
             || (in->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0)
         goto legacy;