PR: 2124
Submitted by: Jan Pechanec <Jan.Pechanec@Sun.COM> Check for memory allocation failures.
This commit is contained in:
@@ -127,7 +127,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;
|
||||
}
|
||||
@@ -299,7 +300,14 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
OPENSSL_free(ctx->md_data);
|
||||
ctx->digest=type;
|
||||
if (type->ctx_size)
|
||||
{
|
||||
ctx->md_data=OPENSSL_malloc(type->ctx_size);
|
||||
if (!ctx->md_data)
|
||||
{
|
||||
EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
skip_to_init:
|
||||
@@ -380,8 +388,17 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
|
||||
|
||||
if (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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user