PR: 2124
Submitted by: Jan Pechanec <Jan.Pechanec@Sun.COM> Check for memory allocation failures.
This commit is contained in:
parent
cb4823fdd6
commit
9e5dea0ffd
@ -127,7 +127,8 @@ EVP_MD_CTX *EVP_MD_CTX_create(void)
|
|||||||
{
|
{
|
||||||
EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
|
EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
|
||||||
|
|
||||||
EVP_MD_CTX_init(ctx);
|
if (ctx)
|
||||||
|
EVP_MD_CTX_init(ctx);
|
||||||
|
|
||||||
return 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);
|
OPENSSL_free(ctx->md_data);
|
||||||
ctx->digest=type;
|
ctx->digest=type;
|
||||||
if (type->ctx_size)
|
if (type->ctx_size)
|
||||||
|
{
|
||||||
ctx->md_data=OPENSSL_malloc(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
|
#ifndef OPENSSL_NO_ENGINE
|
||||||
skip_to_init:
|
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 (out->digest->ctx_size)
|
||||||
{
|
{
|
||||||
if (tmp_buf) out->md_data = tmp_buf;
|
if (tmp_buf)
|
||||||
else out->md_data=OPENSSL_malloc(out->digest->ctx_size);
|
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);
|
memcpy(out->md_data,in->md_data,out->digest->ctx_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,16 +305,40 @@ void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
|
|||||||
static void expand(LHASH *lh)
|
static void expand(LHASH *lh)
|
||||||
{
|
{
|
||||||
LHASH_NODE **n,**n1,**n2,*np;
|
LHASH_NODE **n,**n1,**n2,*np;
|
||||||
unsigned int p,i,j;
|
unsigned int p,i,j,pmax;
|
||||||
unsigned long hash,nni;
|
unsigned long hash,nni;
|
||||||
|
|
||||||
|
p=(int)lh->p++;
|
||||||
|
nni=lh->num_alloc_nodes;
|
||||||
|
pmax=lh->pmax;
|
||||||
|
|
||||||
|
if ((lh->p) >= lh->pmax)
|
||||||
|
{
|
||||||
|
j=(int)lh->num_alloc_nodes*2;
|
||||||
|
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
|
||||||
|
(int)sizeof(LHASH_NODE *)*j);
|
||||||
|
if (n == NULL)
|
||||||
|
{
|
||||||
|
/* fputs("realloc error in lhash",stderr); */
|
||||||
|
lh->error++;
|
||||||
|
lh->p=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* else */
|
||||||
|
for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
|
||||||
|
n[i]=NULL; /* 02/03/92 eay */
|
||||||
|
lh->pmax=lh->num_alloc_nodes;
|
||||||
|
lh->num_alloc_nodes=j;
|
||||||
|
lh->num_expand_reallocs++;
|
||||||
|
lh->p=0;
|
||||||
|
lh->b=n;
|
||||||
|
}
|
||||||
|
|
||||||
lh->num_nodes++;
|
lh->num_nodes++;
|
||||||
lh->num_expands++;
|
lh->num_expands++;
|
||||||
p=(int)lh->p++;
|
|
||||||
n1= &(lh->b[p]);
|
n1= &(lh->b[p]);
|
||||||
n2= &(lh->b[p+(int)lh->pmax]);
|
n2= &(lh->b[p+pmax]);
|
||||||
*n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
|
*n2=NULL; /* 27/07/92 - eay - undefined pointer bug */
|
||||||
nni=lh->num_alloc_nodes;
|
|
||||||
|
|
||||||
for (np= *n1; np != NULL; )
|
for (np= *n1; np != NULL; )
|
||||||
{
|
{
|
||||||
@ -335,35 +359,14 @@ static void expand(LHASH *lh)
|
|||||||
np= *n1;
|
np= *n1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lh->p) >= lh->pmax)
|
|
||||||
{
|
|
||||||
j=(int)lh->num_alloc_nodes*2;
|
|
||||||
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
|
|
||||||
(int)(sizeof(LHASH_NODE *)*j));
|
|
||||||
if (n == NULL)
|
|
||||||
{
|
|
||||||
/* fputs("realloc error in lhash",stderr); */
|
|
||||||
lh->error++;
|
|
||||||
lh->p=0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/* else */
|
|
||||||
for (i=(int)lh->num_alloc_nodes; i<j; i++)/* 26/02/92 eay */
|
|
||||||
n[i]=NULL; /* 02/03/92 eay */
|
|
||||||
lh->pmax=lh->num_alloc_nodes;
|
|
||||||
lh->num_alloc_nodes=j;
|
|
||||||
lh->num_expand_reallocs++;
|
|
||||||
lh->p=0;
|
|
||||||
lh->b=n;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void contract(LHASH *lh)
|
static void contract(LHASH *lh)
|
||||||
{
|
{
|
||||||
LHASH_NODE **n,*n1,*np;
|
LHASH_NODE **n,*n1,*np;
|
||||||
|
int idx = lh->p+lh->pmax-1;
|
||||||
|
|
||||||
np=lh->b[lh->p+lh->pmax-1];
|
np=lh->b[idx];
|
||||||
lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
|
|
||||||
if (lh->p == 0)
|
if (lh->p == 0)
|
||||||
{
|
{
|
||||||
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
|
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
|
||||||
@ -383,6 +386,7 @@ static void contract(LHASH *lh)
|
|||||||
else
|
else
|
||||||
lh->p--;
|
lh->p--;
|
||||||
|
|
||||||
|
lh->b[idx] = NULL;
|
||||||
lh->num_nodes--;
|
lh->num_nodes--;
|
||||||
lh->num_contracts++;
|
lh->num_contracts++;
|
||||||
|
|
||||||
|
@ -208,7 +208,16 @@ RSA *RSA_new_method(ENGINE *engine)
|
|||||||
ret->mt_blinding=NULL;
|
ret->mt_blinding=NULL;
|
||||||
ret->bignum_data=NULL;
|
ret->bignum_data=NULL;
|
||||||
ret->flags=ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW;
|
ret->flags=ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW;
|
||||||
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
|
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data))
|
||||||
|
{
|
||||||
|
#ifndef OPENSSL_NO_ENGINE
|
||||||
|
if (ret->engine)
|
||||||
|
ENGINE_finish(ret->engine);
|
||||||
|
#endif
|
||||||
|
OPENSSL_free(ret);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret->meth->init != NULL) && !ret->meth->init(ret))
|
if ((ret->meth->init != NULL) && !ret->meth->init(ret))
|
||||||
{
|
{
|
||||||
#ifndef OPENSSL_NO_ENGINE
|
#ifndef OPENSSL_NO_ENGINE
|
||||||
|
@ -198,7 +198,13 @@ X509_STORE *X509_STORE_new(void)
|
|||||||
ret->cert_crl = 0;
|
ret->cert_crl = 0;
|
||||||
ret->cleanup = 0;
|
ret->cleanup = 0;
|
||||||
|
|
||||||
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data);
|
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data))
|
||||||
|
{
|
||||||
|
sk_X509_OBJECT_free(ret->objs);
|
||||||
|
OPENSSL_free(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ret->references=1;
|
ret->references=1;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user