Fix EVP_PKEY_CTX_dup() to return correct value and handle NULL keys in
[openssl.git] / crypto / evp / pmeth_lib.c
index 49a8ee99cb20cff4f8f63b5b702f3a9838d79b6d..5b8000d691c2f4667b9d20a94457eb0f6d5a5086 100644 (file)
@@ -252,23 +252,21 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
 #endif
 
        if (pctx->pkey)
-               {
                CRYPTO_add(&pctx->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
-               rctx->pkey = pctx->pkey;
-               }
+
+       rctx->pkey = pctx->pkey;
 
        if (pctx->peerkey)
-               {
                CRYPTO_add(&pctx->peerkey->references,1,CRYPTO_LOCK_EVP_PKEY);
-               rctx->peerkey = pctx->peerkey;
-               }
+
+       rctx->peerkey = pctx->peerkey;
 
        rctx->data = NULL;
        rctx->app_data = NULL;
        rctx->operation = pctx->operation;
 
        if (pctx->pmeth->copy(rctx, pctx) > 0)
-               return pctx;
+               return rctx;
 
        EVP_PKEY_CTX_free(rctx);
        return NULL;