]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
EVP_PKEY_derive_set_peer_ex(): Don't free peer on error
authorAndrew Dinh <andrewd@openssl.org>
Wed, 19 Feb 2025 06:29:07 +0000 (13:29 +0700)
committerTomas Mraz <tomas@openssl.org>
Tue, 25 Feb 2025 14:47:08 +0000 (15:47 +0100)
In EVP_PKEY_derive_set_peer_ex, don't free peer
on error. Revert to existing functionality.

Bug was introduced with
https://github.com/openssl/openssl/pull/26294

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26823)

crypto/evp/exchange.c

index 0c27d34ba44f548375adfd4b1e347f3b57104610..a24b54dd71b4e2b54608ab722926155a19786a25 100644 (file)
@@ -494,20 +494,15 @@ int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer,
         return -1;
     }
 
+    ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer);
+    if (ret <= 0)
+        return ret;
     if (!EVP_PKEY_up_ref(peer))
         return -1;
 
     EVP_PKEY_free(ctx->peerkey);
     ctx->peerkey = peer;
 
-    ret = ctx->pmeth->ctrl(ctx, EVP_PKEY_CTRL_PEER_KEY, 1, peer);
-
-    if (ret <= 0) {
-        EVP_PKEY_free(ctx->peerkey);
-        ctx->peerkey = NULL;
-        return ret;
-    }
-
     return 1;
 #endif
 }