PR: 2124
[openssl.git] / crypto / evp / digest.c
index acada47fda02740e77cfef1783bbe510a53c5c03..d6abcfe1d6604a47e9b21a859452075ccbeb5a0d 100644 (file)
@@ -126,7 +126,8 @@ EVP_MD_CTX *EVP_MD_CTX_create(void)
        {
        EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
 
-       EVP_MD_CTX_init(ctx);
+       if (ctx)
+               EVP_MD_CTX_init(ctx);
 
        return ctx;
        }
@@ -286,8 +287,17 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
 
        if (in->md_data && out->digest->ctx_size)
                {
-               if (tmp_buf) out->md_data = tmp_buf;
-               else out->md_data=OPENSSL_malloc(out->digest->ctx_size);
+               if (tmp_buf)
+                       out->md_data = tmp_buf;
+               else
+                       {
+                       out->md_data=OPENSSL_malloc(out->digest->ctx_size);
+                       if (!out->md_data)
+                               {
+                               EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,ERR_R_MALLOC_FAILURE);
+                               return 0;
+                               }
+                       }
                memcpy(out->md_data,in->md_data,out->digest->ctx_size);
                }