Fix double free in d2i_PrivateKey().
[openssl.git] / crypto / evp / p_sign.c
index da17514df0b635d4dc61b06b8c6ae2fe855d3dd3..46d2dccffce1168621e9b4974d72922e11d39449 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/evp/p_sign.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -61,6 +60,7 @@
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 #include <openssl/x509.h>
+#include "internal/evp_int.h"
 
 int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
                   unsigned int *siglen, EVP_PKEY *pkey)
@@ -77,7 +77,7 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
             goto err;
     } else {
         int rv = 0;
-        EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_create();
+        EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
         if (tmp_ctx == NULL) {
             EVPerr(EVP_F_EVP_SIGNFINAL, ERR_R_MALLOC_FAILURE);
             return 0;
@@ -85,7 +85,7 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
         rv = EVP_MD_CTX_copy_ex(tmp_ctx, ctx);
         if (rv)
             rv = EVP_DigestFinal_ex(tmp_ctx, m, &m_len);
-        EVP_MD_CTX_destroy(tmp_ctx);
+        EVP_MD_CTX_free(tmp_ctx);
         if (!rv)
             return 0;
     }
@@ -97,7 +97,7 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
         goto err;
     if (EVP_PKEY_sign_init(pkctx) <= 0)
         goto err;
-    if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0)
+    if (EVP_PKEY_CTX_set_signature_md(pkctx, EVP_MD_CTX_md(ctx)) <= 0)
         goto err;
     if (EVP_PKEY_sign(pkctx, sigret, &sltmp, m, m_len) <= 0)
         goto err;