Stop raising ERR_R_MALLOC_FAILURE in most places

Since OPENSSL_malloc() and friends report ERR_R_MALLOC_FAILURE, and
at least handle the file name and line number they are called from,
there's no need to report ERR_R_MALLOC_FAILURE where they are called
directly, or when SSLfatal() and RLAYERfatal() is used, the reason
`ERR_R_MALLOC_FAILURE` is changed to `ERR_R_CRYPTO_LIB`.

There were a number of places where `ERR_R_MALLOC_FAILURE` was reported
even though it was a function from a different sub-system that was
called.  Those places are changed to report ERR_R_{lib}_LIB, where
{lib} is the name of that sub-system.
Some of them are tricky to get right, as we have a lot of functions
that belong in the ASN1 sub-system, and all the `sk_` calls or from
the CRYPTO sub-system.

Some extra adaptation was necessary where there were custom OPENSSL_malloc()
wrappers, and some bugs are fixed alongside these changes.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19301)
This commit is contained in:
Richard Levitte 2022-09-29 13:57:34 +02:00
parent 9167a47f78
commit e077455e9e
380 changed files with 2224 additions and 2782 deletions

View File

@ -82,7 +82,7 @@ ASN1_BIT_STRING *ossl_c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
ASN1_BIT_STRING *ret = NULL; ASN1_BIT_STRING *ret = NULL;
const unsigned char *p; const unsigned char *p;
unsigned char *s; unsigned char *s;
int i; int i = 0;
if (len < 1) { if (len < 1) {
i = ASN1_R_STRING_TOO_SHORT; i = ASN1_R_STRING_TOO_SHORT;
@ -115,7 +115,6 @@ ASN1_BIT_STRING *ossl_c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
if (len-- > 1) { /* using one because of the bits left byte */ if (len-- > 1) { /* using one because of the bits left byte */
s = OPENSSL_malloc((int)len); s = OPENSSL_malloc((int)len);
if (s == NULL) { if (s == NULL) {
i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
} }
memcpy(s, p, (int)len); memcpy(s, p, (int)len);
@ -131,7 +130,8 @@ ASN1_BIT_STRING *ossl_c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
*pp = p; *pp = p;
return ret; return ret;
err: err:
ERR_raise(ERR_LIB_ASN1, i); if (i != 0)
ERR_raise(ERR_LIB_ASN1, i);
if ((a == NULL) || (*a != ret)) if ((a == NULL) || (*a != ret))
ASN1_BIT_STRING_free(ret); ASN1_BIT_STRING_free(ret);
return NULL; return NULL;
@ -160,10 +160,8 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
if (!value) if (!value)
return 1; /* Don't need to set */ return 1; /* Don't need to set */
c = OPENSSL_clear_realloc(a->data, a->length, w + 1); c = OPENSSL_clear_realloc(a->data, a->length, w + 1);
if (c == NULL) { if (c == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
if (w + 1 - a->length > 0) if (w + 1 - a->length > 0)
memset(c + a->length, 0, w + 1 - a->length); memset(c + a->length, 0, w + 1 - a->length);
a->data = c; a->data = c;

View File

@ -123,7 +123,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
b = BUF_MEM_new(); b = BUF_MEM_new();
if (b == NULL) { if (b == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
return -1; return -1;
} }
@ -134,7 +134,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
want -= diff; want -= diff;
if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) { if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
goto err; goto err;
} }
i = BIO_read(in, &(b->data[len]), want); i = BIO_read(in, &(b->data[len]), want);
@ -206,7 +206,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
size_t chunk = want > chunk_max ? chunk_max : want; size_t chunk = want > chunk_max ? chunk_max : want;
if (!BUF_MEM_grow_clean(b, len + chunk)) { if (!BUF_MEM_grow_clean(b, len + chunk)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
goto err; goto err;
} }
want -= chunk; want -= chunk;

View File

@ -36,10 +36,8 @@ int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR); ERR_raise(ERR_LIB_ASN1, ERR_R_INTERNAL_ERROR);
return 0; return 0;
} }
if ((str = OPENSSL_malloc(inl)) == NULL) { if ((str = OPENSSL_malloc(inl)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
p = str; p = str;
i2d(data, &p); i2d(data, &p);

View File

@ -28,10 +28,8 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x)
return NULL; return NULL;
b = OPENSSL_malloc(i + 10); b = OPENSSL_malloc(i + 10);
if (b == NULL) { if (b == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
p = b; p = b;
i = i2d(x, &p); i = i2d(x, &p);
p2 = b; p2 = b;
@ -78,7 +76,7 @@ void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)
i = ASN1_item_i2d(x, &b, it); i = ASN1_item_i2d(x, &b, it);
if (b == NULL) { if (b == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return NULL; return NULL;
} }
p = b; p = b;

View File

@ -42,10 +42,8 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x)
return 0; return 0;
b = OPENSSL_malloc(n); b = OPENSSL_malloc(n);
if (b == NULL) { if (b == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
p = (unsigned char *)b; p = (unsigned char *)b;
i2d(x, &p); i2d(x, &p);
@ -91,7 +89,7 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x)
n = ASN1_item_i2d(x, &b, it); n = ASN1_item_i2d(x, &b, it);
if (b == NULL) { if (b == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0; return 0;
} }

View File

@ -303,8 +303,10 @@ ASN1_INTEGER *ossl_c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
} else } else
ret = *a; ret = *a;
if (ASN1_STRING_set(ret, NULL, r) == 0) if (ASN1_STRING_set(ret, NULL, r) == 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
}
c2i_ibuf(ret->data, &neg, *pp, len); c2i_ibuf(ret->data, &neg, *pp, len);
@ -318,7 +320,6 @@ ASN1_INTEGER *ossl_c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
(*a) = ret; (*a) = ret;
return ret; return ret;
err: err:
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
if (a == NULL || *a != ret) if (a == NULL || *a != ret)
ASN1_INTEGER_free(ret); ASN1_INTEGER_free(ret);
return NULL; return NULL;
@ -400,7 +401,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
unsigned char *s; unsigned char *s;
long len = 0; long len = 0;
int inf, tag, xclass; int inf, tag, xclass;
int i; int i = 0;
if ((a == NULL) || ((*a) == NULL)) { if ((a == NULL) || ((*a) == NULL)) {
if ((ret = ASN1_INTEGER_new()) == NULL) if ((ret = ASN1_INTEGER_new()) == NULL)
@ -430,10 +431,8 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
* a missing NULL parameter. * a missing NULL parameter.
*/ */
s = OPENSSL_malloc((int)len + 1); s = OPENSSL_malloc((int)len + 1);
if (s == NULL) { if (s == NULL)
i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
}
ret->type = V_ASN1_INTEGER; ret->type = V_ASN1_INTEGER;
if (len) { if (len) {
if ((*p == 0) && (len != 1)) { if ((*p == 0) && (len != 1)) {
@ -450,7 +449,8 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
*pp = p; *pp = p;
return ret; return ret;
err: err:
ERR_raise(ERR_LIB_ASN1, i); if (i != 0)
ERR_raise(ERR_LIB_ASN1, i);
if ((a == NULL) || (*a != ret)) if ((a == NULL) || (*a != ret))
ASN1_INTEGER_free(ret); ASN1_INTEGER_free(ret);
return NULL; return NULL;
@ -483,7 +483,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
len = 1; len = 1;
if (ASN1_STRING_set(ret, NULL, len) == 0) { if (ASN1_STRING_set(ret, NULL, len) == 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }

View File

@ -145,7 +145,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
free_out = 1; free_out = 1;
dest = ASN1_STRING_type_new(str_type); dest = ASN1_STRING_type_new(str_type);
if (dest == NULL) { if (dest == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return -1; return -1;
} }
*out = dest; *out = dest;
@ -153,7 +153,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
/* If both the same type just copy across */ /* If both the same type just copy across */
if (inform == outform) { if (inform == outform) {
if (!ASN1_STRING_set(dest, in, len)) { if (!ASN1_STRING_set(dest, in, len)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return -1; return -1;
} }
return str_type; return str_type;
@ -185,7 +185,6 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
if ((p = OPENSSL_malloc(outlen + 1)) == NULL) { if ((p = OPENSSL_malloc(outlen + 1)) == NULL) {
if (free_out) if (free_out)
ASN1_STRING_free(dest); ASN1_STRING_free(dest);
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return -1; return -1;
} }
dest->length = outlen; dest->length = outlen;

View File

@ -31,10 +31,8 @@ int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
return objsize; return objsize;
if (*pp == NULL) { if (*pp == NULL) {
if ((p = allocated = OPENSSL_malloc(objsize)) == NULL) { if ((p = allocated = OPENSSL_malloc(objsize)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
} else { } else {
p = *pp; p = *pp;
} }
@ -135,10 +133,8 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
OPENSSL_free(tmp); OPENSSL_free(tmp);
tmpsize = blsize + 32; tmpsize = blsize + 32;
tmp = OPENSSL_malloc(tmpsize); tmp = OPENSSL_malloc(tmpsize);
if (tmp == NULL) { if (tmp == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
} }
while (blsize--) { while (blsize--) {
BN_ULONG t = BN_div_word(bl, 0x80L); BN_ULONG t = BN_div_word(bl, 0x80L);
@ -196,10 +192,8 @@ int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
ERR_raise(ERR_LIB_ASN1, ASN1_R_LENGTH_TOO_LONG); ERR_raise(ERR_LIB_ASN1, ASN1_R_LENGTH_TOO_LONG);
return -1; return -1;
} }
if ((p = OPENSSL_malloc(i + 1)) == NULL) { if ((p = OPENSSL_malloc(i + 1)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return -1; return -1;
}
i2t_ASN1_OBJECT(p, i + 1, a); i2t_ASN1_OBJECT(p, i + 1, a);
} }
if (i <= 0) { if (i <= 0) {
@ -308,10 +302,8 @@ ASN1_OBJECT *ossl_c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
ret->length = 0; ret->length = 0;
OPENSSL_free(data); OPENSSL_free(data);
data = OPENSSL_malloc(length); data = OPENSSL_malloc(length);
if (data == NULL) { if (data == NULL)
i = ERR_R_MALLOC_FAILURE;
goto err; goto err;
}
ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA; ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
} }
memcpy(data, p, length); memcpy(data, p, length);
@ -345,10 +337,8 @@ ASN1_OBJECT *ASN1_OBJECT_new(void)
ASN1_OBJECT *ret; ASN1_OBJECT *ret;
ret = OPENSSL_zalloc(sizeof(*ret)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC; ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
return ret; return ret;
} }

View File

@ -35,7 +35,7 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
X509_ALGOR *a; X509_ALGOR *a;
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err; goto err;
} }
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
@ -82,7 +82,6 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
buf_out = OPENSSL_malloc(outll); buf_out = OPENSSL_malloc(outll);
if (buf_in == NULL || buf_out == NULL) { if (buf_in == NULL || buf_out == NULL) {
outl = 0; outl = 0;
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
p = buf_in; p = buf_in;
@ -130,7 +129,7 @@ int ASN1_item_sign_ex(const ASN1_ITEM *it, X509_ALGOR *algor1,
EVP_MD_CTX *ctx = evp_md_ctx_new_ex(pkey, id, libctx, propq); EVP_MD_CTX *ctx = evp_md_ctx_new_ex(pkey, id, libctx, propq);
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return 0; return 0;
} }
/* We can use the non _ex variant here since the pkey is already setup */ /* We can use the non _ex variant here since the pkey is already setup */
@ -270,7 +269,6 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1,
buf_out = OPENSSL_malloc(outll); buf_out = OPENSSL_malloc(outll);
if (buf_in == NULL || buf_out == NULL) { if (buf_in == NULL || buf_out == NULL) {
outl = 0; outl = 0;
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }

View File

@ -282,10 +282,8 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg,
der_len = i2d_ASN1_TYPE(&t, NULL); der_len = i2d_ASN1_TYPE(&t, NULL);
if (der_len <= 0) if (der_len <= 0)
return -1; return -1;
if ((der_buf = OPENSSL_malloc(der_len)) == NULL) { if ((der_buf = OPENSSL_malloc(der_len)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return -1; return -1;
}
p = der_buf; p = der_buf;
i2d_ASN1_TYPE(&t, &p); i2d_ASN1_TYPE(&t, &p);
outlen = do_hex_dump(io_ch, arg, der_buf, der_len); outlen = do_hex_dump(io_ch, arg, der_buf, der_len);

View File

@ -159,10 +159,8 @@ static ASN1_STRING_TABLE *stable_get(int nid)
tmp = ASN1_STRING_TABLE_get(nid); tmp = ASN1_STRING_TABLE_get(nid);
if (tmp != NULL && tmp->flags & STABLE_FLAGS_MALLOC) if (tmp != NULL && tmp->flags & STABLE_FLAGS_MALLOC)
return tmp; return tmp;
if ((rv = OPENSSL_zalloc(sizeof(*rv))) == NULL) { if ((rv = OPENSSL_zalloc(sizeof(*rv))) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
if (!sk_ASN1_STRING_TABLE_push(stable, rv)) { if (!sk_ASN1_STRING_TABLE_push(stable, rv)) {
OPENSSL_free(rv); OPENSSL_free(rv);
return NULL; return NULL;
@ -190,7 +188,7 @@ int ASN1_STRING_TABLE_add(int nid,
tmp = stable_get(nid); tmp = stable_get(nid);
if (tmp == NULL) { if (tmp == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0; return 0;
} }
if (minsize >= 0) if (minsize >= 0)

View File

@ -420,10 +420,8 @@ int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str)
* new t.data would be freed after ASN1_STRING_copy is done. * new t.data would be freed after ASN1_STRING_copy is done.
*/ */
t.data = OPENSSL_zalloc(t.length + 1); t.data = OPENSSL_zalloc(t.length + 1);
if (t.data == NULL) { if (t.data == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto out; goto out;
}
memcpy(t.data, str + 2, t.length); memcpy(t.data, str + 2, t.length);
t.type = V_ASN1_UTCTIME; t.type = V_ASN1_UTCTIME;
} }

View File

@ -33,7 +33,7 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
int ret = -1, i, inl; int ret = -1, i, inl;
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err; goto err;
} }
i = OBJ_obj2nid(a->algorithm); i = OBJ_obj2nid(a->algorithm);
@ -54,10 +54,8 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
goto err; goto err;
} }
buf_in = OPENSSL_malloc((unsigned int)inl); buf_in = OPENSSL_malloc((unsigned int)inl);
if (buf_in == NULL) { if (buf_in == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
p = buf_in; p = buf_in;
i2d(data, &p); i2d(data, &p);
@ -206,7 +204,7 @@ int ASN1_item_verify_ctx(const ASN1_ITEM *it, const X509_ALGOR *alg,
goto err; goto err;
} }
if (buf_in == NULL) { if (buf_in == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }
inll = inl; inll = inl;

View File

@ -222,10 +222,8 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
{ {
EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth)); EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth));
if (ameth == NULL) { if (ameth == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ameth->pkey_id = id; ameth->pkey_id = id;
ameth->pkey_base_id = id; ameth->pkey_base_id = id;
@ -247,7 +245,6 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
err: err:
EVP_PKEY_asn1_free(ameth); EVP_PKEY_asn1_free(ameth);
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }

View File

@ -581,7 +581,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
int no_unused = 1; int no_unused = 1;
if ((atmp = ASN1_TYPE_new()) == NULL) { if ((atmp = ASN1_TYPE_new()) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return NULL; return NULL;
} }
@ -642,11 +642,11 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
goto bad_form; goto bad_form;
} }
if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) { if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto bad_str; goto bad_str;
} }
if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) { if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto bad_str; goto bad_str;
} }
atmp->value.asn1_string->type = utype; atmp->value.asn1_string->type = utype;
@ -677,7 +677,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
-1, format, ASN1_tag2bit(utype)) <= 0) { -1, format, ASN1_tag2bit(utype)) <= 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto bad_str; goto bad_str;
} }
@ -686,7 +686,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_BIT_STRING: case V_ASN1_BIT_STRING:
case V_ASN1_OCTET_STRING: case V_ASN1_OCTET_STRING:
if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) { if ((atmp->value.asn1_string = ASN1_STRING_new()) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto bad_form; goto bad_form;
} }
@ -750,7 +750,7 @@ static int bitstr_cb(const char *elem, int len, void *bitstr)
return 0; return 0;
} }
if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) { if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0; return 0;
} }
return 1; return 1;

View File

@ -314,7 +314,6 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len_in)
str->data = OPENSSL_realloc(c, len + 1); str->data = OPENSSL_realloc(c, len + 1);
#endif #endif
if (str->data == NULL) { if (str->data == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
str->data = c; str->data = c;
return 0; return 0;
} }
@ -354,10 +353,8 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
ASN1_STRING *ret; ASN1_STRING *ret;
ret = OPENSSL_zalloc(sizeof(*ret)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->type = type; ret->type = type;
return ret; return ret;
} }

View File

@ -76,7 +76,7 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
BIO *bio, *tbio; BIO *bio, *tbio;
bio = BIO_new_NDEF(out, val, it); bio = BIO_new_NDEF(out, val, it);
if (!bio) { if (!bio) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
return 0; return 0;
} }
if (!SMIME_crlf_copy(in, bio, flags)) { if (!SMIME_crlf_copy(in, bio, flags)) {
@ -109,7 +109,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
int r; int r;
b64 = BIO_new(BIO_f_base64()); b64 = BIO_new(BIO_f_base64());
if (b64 == NULL) { if (b64 == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BIO_LIB);
return 0; return 0;
} }
/* /*
@ -142,7 +142,7 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it, ASN1_VALUE **x,
ASN1_VALUE *val; ASN1_VALUE *val;
if ((b64 = BIO_new(BIO_f_base64())) == NULL) { if ((b64 = BIO_new(BIO_f_base64())) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BIO_LIB);
return 0; return 0;
} }
bio = BIO_push(b64, bio); bio = BIO_push(b64, bio);
@ -521,7 +521,7 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
*/ */
bf = BIO_new(BIO_f_buffer()); bf = BIO_new(BIO_f_buffer());
if (bf == NULL) { if (bf == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BIO_LIB);
return 0; return 0;
} }
out = BIO_push(bf, out); out = BIO_push(bf, out);

View File

@ -83,10 +83,8 @@ static int do_create(const char *value, const char *name)
p--; p--;
} }
p++; p++;
if ((lntmp = OPENSSL_malloc((p - ln) + 1)) == NULL) { if ((lntmp = OPENSSL_malloc((p - ln) + 1)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
memcpy(lntmp, ln, p - ln); memcpy(lntmp, ln, p - ln);
lntmp[p - ln] = '\0'; lntmp[p - ln] = '\0';
ln = lntmp; ln = lntmp;

View File

@ -106,7 +106,7 @@ static int do_tcreate(const char *value, const char *name)
rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max, rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max,
tbl_mask, tbl_flags); tbl_mask, tbl_flags);
if (!rv) if (!rv)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
} }
sk_CONF_VALUE_pop_free(lst, X509V3_conf_free); sk_CONF_VALUE_pop_free(lst, X509V3_conf_free);
return rv; return rv;

View File

@ -19,7 +19,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
if (oct == NULL || *oct == NULL) { if (oct == NULL || *oct == NULL) {
if ((octmp = ASN1_STRING_new()) == NULL) { if ((octmp = ASN1_STRING_new()) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return NULL; return NULL;
} }
} else { } else {
@ -33,7 +33,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
goto err; goto err;
} }
if (octmp->data == NULL) { if (octmp->data == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }

View File

@ -100,10 +100,8 @@ static int asn1_bio_new(BIO *b)
{ {
BIO_ASN1_BUF_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); BIO_ASN1_BUF_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx == NULL) { if (ctx == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) { if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) {
OPENSSL_free(ctx); OPENSSL_free(ctx);
return 0; return 0;
@ -116,10 +114,12 @@ static int asn1_bio_new(BIO *b)
static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
{ {
if (size <= 0 || (ctx->buf = OPENSSL_malloc(size)) == NULL) { if (size <= 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_INVALID_ARGUMENT);
return 0; return 0;
} }
if ((ctx->buf = OPENSSL_malloc(size)) == NULL)
return 0;
ctx->bufsize = size; ctx->bufsize = size;
ctx->asn1_class = V_ASN1_UNIVERSAL; ctx->asn1_class = V_ASN1_UNIVERSAL;
ctx->asn1_tag = V_ASN1_OCTET_STRING; ctx->asn1_tag = V_ASN1_OCTET_STRING;

View File

@ -116,10 +116,8 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
if (derlen < 0) if (derlen < 0)
return 0; return 0;
if ((p = OPENSSL_malloc(derlen)) == NULL) { if ((p = OPENSSL_malloc(derlen)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ndef_aux->derbuf = p; ndef_aux->derbuf = p;
*pbuf = p; *pbuf = p;
@ -191,10 +189,8 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
if (derlen < 0) if (derlen < 0)
return 0; return 0;
if ((p = OPENSSL_malloc(derlen)) == NULL) { if ((p = OPENSSL_malloc(derlen)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ndef_aux->derbuf = p; ndef_aux->derbuf = p;
*pbuf = p; *pbuf = p;

View File

@ -108,7 +108,6 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
if (num + i > slen) { if (num + i > slen) {
sp = OPENSSL_clear_realloc(s, slen, num + i * 2); sp = OPENSSL_clear_realloc(s, slen, num + i * 2);
if (sp == NULL) { if (sp == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
OPENSSL_free(s); OPENSSL_free(s);
return 0; return 0;
} }

View File

@ -99,7 +99,6 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
if (num + i > slen) { if (num + i > slen) {
sp = OPENSSL_realloc(s, (unsigned int)num + i * 2); sp = OPENSSL_realloc(s, (unsigned int)num + i * 2);
if (sp == NULL) { if (sp == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
OPENSSL_free(s); OPENSSL_free(s);
return 0; return 0;
} }

View File

@ -34,13 +34,14 @@ int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter,
pbe = PBEPARAM_new(); pbe = PBEPARAM_new();
if (pbe == NULL) { if (pbe == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); /* ERR_R_ASN1_LIB, because PBEPARAM_new() is defined in crypto/asn1 */
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }
if (iter <= 0) if (iter <= 0)
iter = PKCS5_DEFAULT_ITER; iter = PKCS5_DEFAULT_ITER;
if (!ASN1_INTEGER_set(pbe->iter, iter)) { if (!ASN1_INTEGER_set(pbe->iter, iter)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }
if (!saltlen) if (!saltlen)
@ -49,10 +50,8 @@ int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter,
goto err; goto err;
sstr = OPENSSL_malloc(saltlen); sstr = OPENSSL_malloc(saltlen);
if (sstr == NULL) { if (sstr == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (salt) if (salt)
memcpy(sstr, salt, saltlen); memcpy(sstr, salt, saltlen);
else if (RAND_bytes_ex(ctx, sstr, saltlen, 0) <= 0) else if (RAND_bytes_ex(ctx, sstr, saltlen, 0) <= 0)
@ -62,7 +61,7 @@ int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter,
sstr = NULL; sstr = NULL;
if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) { if (!ASN1_item_pack(pbe, ASN1_ITEM_rptr(PBEPARAM), &pbe_str)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -94,7 +93,7 @@ X509_ALGOR *PKCS5_pbe_set_ex(int alg, int iter,
X509_ALGOR *ret; X509_ALGOR *ret;
ret = X509_ALGOR_new(); ret = X509_ALGOR_new();
if (ret == NULL) { if (ret == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
return NULL; return NULL;
} }

View File

@ -57,14 +57,18 @@ X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter,
goto err; goto err;
} }
if ((pbe2 = PBE2PARAM_new()) == NULL) if ((pbe2 = PBE2PARAM_new()) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* Setup the AlgorithmIdentifier for the encryption scheme */ /* Setup the AlgorithmIdentifier for the encryption scheme */
scheme = pbe2->encryption; scheme = pbe2->encryption;
scheme->algorithm = OBJ_nid2obj(alg_nid); scheme->algorithm = OBJ_nid2obj(alg_nid);
if ((scheme->parameter = ASN1_TYPE_new()) == NULL) if ((scheme->parameter = ASN1_TYPE_new()) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* Create random IV */ /* Create random IV */
ivlen = EVP_CIPHER_get_iv_length(cipher); ivlen = EVP_CIPHER_get_iv_length(cipher);
@ -76,8 +80,10 @@ X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter,
} }
ctx = EVP_CIPHER_CTX_new(); ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL) if (ctx == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err;
}
/* Dummy cipherinit to just setup the IV, and PRF */ /* Dummy cipherinit to just setup the IV, and PRF */
if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0)) if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0))
@ -113,30 +119,33 @@ X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter,
pbe2->keyfunc = PKCS5_pbkdf2_set_ex(iter, salt, saltlen, prf_nid, keylen, pbe2->keyfunc = PKCS5_pbkdf2_set_ex(iter, salt, saltlen, prf_nid, keylen,
libctx); libctx);
if (pbe2->keyfunc == NULL) if (pbe2->keyfunc == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* Now set up top level AlgorithmIdentifier */ /* Now set up top level AlgorithmIdentifier */
if ((ret = X509_ALGOR_new()) == NULL) if ((ret = X509_ALGOR_new()) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
goto err;
}
ret->algorithm = OBJ_nid2obj(NID_pbes2); ret->algorithm = OBJ_nid2obj(NID_pbes2);
/* Encode PBE2PARAM into parameter */ /* Encode PBE2PARAM into parameter */
if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2, if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2,
&ret->parameter)) &ret->parameter)) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
PBE2PARAM_free(pbe2); PBE2PARAM_free(pbe2);
pbe2 = NULL; pbe2 = NULL;
return ret; return ret;
merr:
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
err: err:
EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_CTX_free(ctx);
PBE2PARAM_free(pbe2); PBE2PARAM_free(pbe2);
@ -170,69 +179,89 @@ X509_ALGOR *PKCS5_pbkdf2_set_ex(int iter, unsigned char *salt, int saltlen,
PBKDF2PARAM *kdf = NULL; PBKDF2PARAM *kdf = NULL;
ASN1_OCTET_STRING *osalt = NULL; ASN1_OCTET_STRING *osalt = NULL;
if ((kdf = PBKDF2PARAM_new()) == NULL) if ((kdf = PBKDF2PARAM_new()) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
if ((osalt = ASN1_OCTET_STRING_new()) == NULL) goto err;
goto merr; }
if ((osalt = ASN1_OCTET_STRING_new()) == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
kdf->salt->value.octet_string = osalt; kdf->salt->value.octet_string = osalt;
kdf->salt->type = V_ASN1_OCTET_STRING; kdf->salt->type = V_ASN1_OCTET_STRING;
if (saltlen < 0) if (saltlen < 0) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_INVALID_ARGUMENT);
goto err;
}
if (saltlen == 0) if (saltlen == 0)
saltlen = PKCS5_SALT_LEN; saltlen = PKCS5_SALT_LEN;
if ((osalt->data = OPENSSL_malloc(saltlen)) == NULL) if ((osalt->data = OPENSSL_malloc(saltlen)) == NULL)
goto merr; goto err;
osalt->length = saltlen; osalt->length = saltlen;
if (salt) if (salt) {
memcpy(osalt->data, salt, saltlen); memcpy(osalt->data, salt, saltlen);
else if (RAND_bytes_ex(libctx, osalt->data, saltlen, 0) <= 0) } else if (RAND_bytes_ex(libctx, osalt->data, saltlen, 0) <= 0) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_RAND_LIB);
goto err;
}
if (iter <= 0) if (iter <= 0)
iter = PKCS5_DEFAULT_ITER; iter = PKCS5_DEFAULT_ITER;
if (!ASN1_INTEGER_set(kdf->iter, iter)) if (!ASN1_INTEGER_set(kdf->iter, iter)) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* If have a key len set it up */ /* If have a key len set it up */
if (keylen > 0) { if (keylen > 0) {
if ((kdf->keylength = ASN1_INTEGER_new()) == NULL) if ((kdf->keylength = ASN1_INTEGER_new()) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
if (!ASN1_INTEGER_set(kdf->keylength, keylen)) goto err;
goto merr; }
if (!ASN1_INTEGER_set(kdf->keylength, keylen)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
} }
/* prf can stay NULL if we are using hmacWithSHA1 */ /* prf can stay NULL if we are using hmacWithSHA1 */
if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) { if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) {
kdf->prf = ossl_X509_ALGOR_from_nid(prf_nid, V_ASN1_NULL, NULL); kdf->prf = ossl_X509_ALGOR_from_nid(prf_nid, V_ASN1_NULL, NULL);
if (kdf->prf == NULL) if (kdf->prf == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
goto err;
}
} }
/* Finally setup the keyfunc structure */ /* Finally setup the keyfunc structure */
keyfunc = X509_ALGOR_new(); keyfunc = X509_ALGOR_new();
if (keyfunc == NULL) if (keyfunc == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
goto err;
}
keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
/* Encode PBKDF2PARAM into parameter of pbe2 */ /* Encode PBKDF2PARAM into parameter of pbe2 */
if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBKDF2PARAM), kdf, if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBKDF2PARAM), kdf,
&keyfunc->parameter)) &keyfunc->parameter)) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
PBKDF2PARAM_free(kdf); PBKDF2PARAM_free(kdf);
return keyfunc; return keyfunc;
merr: err:
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
PBKDF2PARAM_free(kdf); PBKDF2PARAM_free(kdf);
X509_ALGOR_free(keyfunc); X509_ALGOR_free(keyfunc);
return NULL; return NULL;

View File

@ -67,16 +67,20 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
} }
pbe2 = PBE2PARAM_new(); pbe2 = PBE2PARAM_new();
if (pbe2 == NULL) if (pbe2 == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* Setup the AlgorithmIdentifier for the encryption scheme */ /* Setup the AlgorithmIdentifier for the encryption scheme */
scheme = pbe2->encryption; scheme = pbe2->encryption;
scheme->algorithm = OBJ_nid2obj(alg_nid); scheme->algorithm = OBJ_nid2obj(alg_nid);
scheme->parameter = ASN1_TYPE_new(); scheme->parameter = ASN1_TYPE_new();
if (scheme->parameter == NULL) if (scheme->parameter == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* Create random IV */ /* Create random IV */
if (EVP_CIPHER_get_iv_length(cipher)) { if (EVP_CIPHER_get_iv_length(cipher)) {
@ -87,8 +91,10 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
} }
ctx = EVP_CIPHER_CTX_new(); ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL) if (ctx == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err;
}
/* Dummy cipherinit to just setup the IV */ /* Dummy cipherinit to just setup the IV */
if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0) == 0) if (EVP_CipherInit_ex(ctx, cipher, NULL, NULL, iv, 0) == 0)
@ -111,31 +117,34 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
pbe2->keyfunc = pkcs5_scrypt_set(salt, saltlen, keylen, N, r, p); pbe2->keyfunc = pkcs5_scrypt_set(salt, saltlen, keylen, N, r, p);
if (pbe2->keyfunc == NULL) if (pbe2->keyfunc == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* Now set up top level AlgorithmIdentifier */ /* Now set up top level AlgorithmIdentifier */
ret = X509_ALGOR_new(); ret = X509_ALGOR_new();
if (ret == NULL) if (ret == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
ret->algorithm = OBJ_nid2obj(NID_pbes2); ret->algorithm = OBJ_nid2obj(NID_pbes2);
/* Encode PBE2PARAM into parameter */ /* Encode PBE2PARAM into parameter */
if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2, if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2,
&ret->parameter) == NULL) &ret->parameter) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
PBE2PARAM_free(pbe2); PBE2PARAM_free(pbe2);
pbe2 = NULL; pbe2 = NULL;
return ret; return ret;
merr:
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
err: err:
PBE2PARAM_free(pbe2); PBE2PARAM_free(pbe2);
X509_ALGOR_free(ret); X509_ALGOR_free(ret);
@ -151,57 +160,73 @@ static X509_ALGOR *pkcs5_scrypt_set(const unsigned char *salt, size_t saltlen,
X509_ALGOR *keyfunc = NULL; X509_ALGOR *keyfunc = NULL;
SCRYPT_PARAMS *sparam = SCRYPT_PARAMS_new(); SCRYPT_PARAMS *sparam = SCRYPT_PARAMS_new();
if (sparam == NULL) if (sparam == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
if (!saltlen) if (!saltlen)
saltlen = PKCS5_SALT_LEN; saltlen = PKCS5_SALT_LEN;
/* This will either copy salt or grow the buffer */ /* This will either copy salt or grow the buffer */
if (ASN1_STRING_set(sparam->salt, salt, saltlen) == 0) if (ASN1_STRING_set(sparam->salt, salt, saltlen) == 0) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
if (salt == NULL && RAND_bytes(sparam->salt->data, saltlen) <= 0) if (salt == NULL && RAND_bytes(sparam->salt->data, saltlen) <= 0)
goto err; goto err;
if (ASN1_INTEGER_set_uint64(sparam->costParameter, N) == 0) if (ASN1_INTEGER_set_uint64(sparam->costParameter, N) == 0) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
if (ASN1_INTEGER_set_uint64(sparam->blockSize, r) == 0) if (ASN1_INTEGER_set_uint64(sparam->blockSize, r) == 0) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
if (ASN1_INTEGER_set_uint64(sparam->parallelizationParameter, p) == 0) if (ASN1_INTEGER_set_uint64(sparam->parallelizationParameter, p) == 0) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
/* If have a key len set it up */ /* If have a key len set it up */
if (keylen > 0) { if (keylen > 0) {
sparam->keyLength = ASN1_INTEGER_new(); sparam->keyLength = ASN1_INTEGER_new();
if (sparam->keyLength == NULL) if (sparam->keyLength == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
if (ASN1_INTEGER_set_int64(sparam->keyLength, keylen) == 0) goto err;
goto merr; }
if (ASN1_INTEGER_set_int64(sparam->keyLength, keylen) == 0) {
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
} }
/* Finally setup the keyfunc structure */ /* Finally setup the keyfunc structure */
keyfunc = X509_ALGOR_new(); keyfunc = X509_ALGOR_new();
if (keyfunc == NULL) if (keyfunc == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt); keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt);
/* Encode SCRYPT_PARAMS into parameter of pbe2 */ /* Encode SCRYPT_PARAMS into parameter of pbe2 */
if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(SCRYPT_PARAMS), sparam, if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(SCRYPT_PARAMS), sparam,
&keyfunc->parameter) == NULL) &keyfunc->parameter) == NULL) {
goto merr; ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
SCRYPT_PARAMS_free(sparam); SCRYPT_PARAMS_free(sparam);
return keyfunc; return keyfunc;
merr:
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
err: err:
SCRYPT_PARAMS_free(sparam); SCRYPT_PARAMS_free(sparam);
X509_ALGOR_free(keyfunc); X509_ALGOR_free(keyfunc);

View File

@ -629,7 +629,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
} }
if (*val == NULL) { if (*val == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
goto err; goto err;
} }
@ -658,7 +658,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
} }
len -= p - q; len -= p - q;
if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) { if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
ASN1_item_free(skfield, ASN1_ITEM_ptr(tt->item)); ASN1_item_free(skfield, ASN1_ITEM_ptr(tt->item));
goto err; goto err;
} }
@ -802,7 +802,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
len = buf.length; len = buf.length;
/* Append a final null to string */ /* Append a final null to string */
if (!BUF_MEM_grow_clean(&buf, len + 1)) { if (!BUF_MEM_grow_clean(&buf, len + 1)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
goto err; goto err;
} }
buf.data[len] = 0; buf.data[len] = 0;
@ -925,7 +925,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
if (*pval == NULL) { if (*pval == NULL) {
stmp = ASN1_STRING_type_new(utype); stmp = ASN1_STRING_type_new(utype);
if (stmp == NULL) { if (stmp == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err; goto err;
} }
*pval = (ASN1_VALUE *)stmp; *pval = (ASN1_VALUE *)stmp;
@ -939,7 +939,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
*free_cont = 0; *free_cont = 0;
} else { } else {
if (!ASN1_STRING_set(stmp, cont, len)) { if (!ASN1_STRING_set(stmp, cont, len)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
ASN1_STRING_free(stmp); ASN1_STRING_free(stmp);
*pval = NULL; *pval = NULL;
goto err; goto err;
@ -1098,7 +1098,7 @@ static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
if (buf) { if (buf) {
len = buf->length; len = buf->length;
if (!BUF_MEM_grow_clean(buf, len + plen)) { if (!BUF_MEM_grow_clean(buf, len + plen)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
return 0; return 0;
} }
memcpy(buf->data + len, *p, plen); memcpy(buf->data + len, *p, plen);

View File

@ -62,10 +62,8 @@ static int asn1_item_flags_i2d(const ASN1_VALUE *val, unsigned char **out,
len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
if (len <= 0) if (len <= 0)
return len; return len;
if ((buf = OPENSSL_malloc(len)) == NULL) { if ((buf = OPENSSL_malloc(len)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return -1; return -1;
}
p = buf; p = buf;
ASN1_item_ex_i2d(&val, &p, it, -1, flags); ASN1_item_ex_i2d(&val, &p, it, -1, flags);
*out = buf; *out = buf;
@ -415,15 +413,11 @@ static int asn1_set_seq_out(STACK_OF(const_ASN1_VALUE) *sk,
else { else {
derlst = OPENSSL_malloc(sk_const_ASN1_VALUE_num(sk) derlst = OPENSSL_malloc(sk_const_ASN1_VALUE_num(sk)
* sizeof(*derlst)); * sizeof(*derlst));
if (derlst == NULL) { if (derlst == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
tmpdat = OPENSSL_malloc(skcontlen); tmpdat = OPENSSL_malloc(skcontlen);
if (tmpdat == NULL) { if (tmpdat == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
} }
} }
/* If not sorting just output each item */ /* If not sorting just output each item */

View File

@ -78,10 +78,10 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
if (ef != NULL) { if (ef != NULL) {
if (ef->asn1_ex_new_ex != NULL) { if (ef->asn1_ex_new_ex != NULL) {
if (!ef->asn1_ex_new_ex(pval, it, libctx, propq)) if (!ef->asn1_ex_new_ex(pval, it, libctx, propq))
goto memerr; goto asn1err;
} else if (ef->asn1_ex_new != NULL) { } else if (ef->asn1_ex_new != NULL) {
if (!ef->asn1_ex_new(pval, it)) if (!ef->asn1_ex_new(pval, it))
goto memerr; goto asn1err;
} }
} }
break; break;
@ -89,14 +89,14 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
case ASN1_ITYPE_PRIMITIVE: case ASN1_ITYPE_PRIMITIVE:
if (it->templates) { if (it->templates) {
if (!asn1_template_new(pval, it->templates, libctx, propq)) if (!asn1_template_new(pval, it->templates, libctx, propq))
goto memerr; goto asn1err;
} else if (!asn1_primitive_new(pval, it, embed)) } else if (!asn1_primitive_new(pval, it, embed))
goto memerr; goto asn1err;
break; break;
case ASN1_ITYPE_MSTRING: case ASN1_ITYPE_MSTRING:
if (!asn1_primitive_new(pval, it, embed)) if (!asn1_primitive_new(pval, it, embed))
goto memerr; goto asn1err;
break; break;
case ASN1_ITYPE_CHOICE: case ASN1_ITYPE_CHOICE:
@ -113,7 +113,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
} else { } else {
*pval = OPENSSL_zalloc(it->size); *pval = OPENSSL_zalloc(it->size);
if (*pval == NULL) if (*pval == NULL)
goto memerr; return 0;
} }
ossl_asn1_set_choice_selector(pval, -1, it); ossl_asn1_set_choice_selector(pval, -1, it);
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
@ -135,7 +135,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
} else { } else {
*pval = OPENSSL_zalloc(it->size); *pval = OPENSSL_zalloc(it->size);
if (*pval == NULL) if (*pval == NULL)
goto memerr; return 0;
} }
/* 0 : init. lock */ /* 0 : init. lock */
if (ossl_asn1_do_lock(pval, 0, it) < 0) { if (ossl_asn1_do_lock(pval, 0, it) < 0) {
@ -143,13 +143,13 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
OPENSSL_free(*pval); OPENSSL_free(*pval);
*pval = NULL; *pval = NULL;
} }
goto memerr; goto asn1err;
} }
ossl_asn1_enc_init(pval, it); ossl_asn1_enc_init(pval, it);
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
pseqval = ossl_asn1_get_field_ptr(pval, tt); pseqval = ossl_asn1_get_field_ptr(pval, tt);
if (!asn1_template_new(pseqval, tt, libctx, propq)) if (!asn1_template_new(pseqval, tt, libctx, propq))
goto memerr2; goto asn1err2;
} }
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
goto auxerr2; goto auxerr2;
@ -157,10 +157,10 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
} }
return 1; return 1;
memerr2: asn1err2:
ossl_asn1_item_embed_free(pval, it, embed); ossl_asn1_item_embed_free(pval, it, embed);
memerr: asn1err:
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0; return 0;
auxerr2: auxerr2:
@ -230,7 +230,7 @@ static int asn1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
STACK_OF(ASN1_VALUE) *skval; STACK_OF(ASN1_VALUE) *skval;
skval = sk_ASN1_VALUE_new_null(); skval = sk_ASN1_VALUE_new_null();
if (!skval) { if (!skval) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
ret = 0; ret = 0;
goto done; goto done;
} }
@ -298,10 +298,8 @@ static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
return 1; return 1;
case V_ASN1_ANY: case V_ASN1_ANY:
if ((typ = OPENSSL_malloc(sizeof(*typ))) == NULL) { if ((typ = OPENSSL_malloc(sizeof(*typ))) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
typ->value.ptr = NULL; typ->value.ptr = NULL;
typ->type = -1; typ->type = -1;
*pval = (ASN1_VALUE *)typ; *pval = (ASN1_VALUE *)typ;

View File

@ -37,10 +37,8 @@ ASN1_PCTX *ASN1_PCTX_new(void)
ASN1_PCTX *ret; ASN1_PCTX *ret;
ret = OPENSSL_zalloc(sizeof(*ret)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
return ret; return ret;
} }

View File

@ -26,10 +26,8 @@ ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx))
{ {
ASN1_SCTX *ret = OPENSSL_zalloc(sizeof(*ret)); ASN1_SCTX *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->scan_cb = scan_cb; ret->scan_cb = scan_cb;
return ret; return ret;
} }

View File

@ -86,7 +86,7 @@ int ossl_asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
*lck = ret = 1; *lck = ret = 1;
*lock = CRYPTO_THREAD_lock_new(); *lock = CRYPTO_THREAD_lock_new();
if (*lock == NULL) { if (*lock == NULL) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
return -1; return -1;
} }
break; break;
@ -168,10 +168,8 @@ int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
OPENSSL_free(enc->enc); OPENSSL_free(enc->enc);
if (inlen <= 0) if (inlen <= 0)
return 0; return 0;
if ((enc->enc = OPENSSL_malloc(inlen)) == NULL) { if ((enc->enc = OPENSSL_malloc(inlen)) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
memcpy(enc->enc, in, inlen); memcpy(enc->enc, in, inlen);
enc->len = inlen; enc->len = inlen;
enc->modified = 0; enc->modified = 0;

View File

@ -18,10 +18,8 @@ X509_INFO *X509_INFO_new(void)
X509_INFO *ret; X509_INFO *ret;
ret = OPENSSL_zalloc(sizeof(*ret)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
return ret; return ret;
} }

View File

@ -28,10 +28,8 @@
static int uint64_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int uint64_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint64_t))) == NULL) { if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint64_t))) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
return 1; return 1;
} }
@ -123,10 +121,8 @@ static int uint64_print(BIO *out, const ASN1_VALUE **pval, const ASN1_ITEM *it,
static int uint32_new(ASN1_VALUE **pval, const ASN1_ITEM *it) static int uint32_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{ {
if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint32_t))) == NULL) { if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint32_t))) == NULL)
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
return 1; return 1;
} }

View File

@ -19,18 +19,17 @@ X509_PKEY *X509_PKEY_new(void)
ret = OPENSSL_zalloc(sizeof(*ret)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) if (ret == NULL)
goto err; return NULL;
ret->enc_algor = X509_ALGOR_new(); ret->enc_algor = X509_ALGOR_new();
ret->enc_pkey = ASN1_OCTET_STRING_new(); ret->enc_pkey = ASN1_OCTET_STRING_new();
if (ret->enc_algor == NULL || ret->enc_pkey == NULL) if (ret->enc_algor == NULL || ret->enc_pkey == NULL) {
goto err; X509_PKEY_free(ret);
ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return NULL;
}
return ret; return ret;
err:
X509_PKEY_free(ret);
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL;
} }
void X509_PKEY_free(X509_PKEY *x) void X509_PKEY_free(X509_PKEY *x)

View File

@ -119,7 +119,6 @@ int async_fibre_makecontext(async_fibre *fibre)
makecontext(&fibre->fibre, async_start_func, 0); makecontext(&fibre->fibre, async_start_func, 0);
return 1; return 1;
} }
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE);
} else { } else {
fibre->fibre.uc_stack.ss_sp = NULL; fibre->fibre.uc_stack.ss_sp = NULL;
} }

View File

@ -40,10 +40,8 @@ static async_ctx *async_ctx_new(void)
return NULL; return NULL;
nctx = OPENSSL_malloc(sizeof(*nctx)); nctx = OPENSSL_malloc(sizeof(*nctx));
if (nctx == NULL) { if (nctx == NULL)
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
async_fibre_init_dispatcher(&nctx->dispatcher); async_fibre_init_dispatcher(&nctx->dispatcher);
nctx->currjob = NULL; nctx->currjob = NULL;
@ -82,10 +80,8 @@ static ASYNC_JOB *async_job_new(void)
ASYNC_JOB *job = NULL; ASYNC_JOB *job = NULL;
job = OPENSSL_zalloc(sizeof(*job)); job = OPENSSL_zalloc(sizeof(*job));
if (job == NULL) { if (job == NULL)
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
job->status = ASYNC_JOB_RUNNING; job->status = ASYNC_JOB_RUNNING;
@ -256,7 +252,6 @@ int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *wctx, int *ret,
if (args != NULL) { if (args != NULL) {
ctx->currjob->funcargs = OPENSSL_malloc(size); ctx->currjob->funcargs = OPENSSL_malloc(size);
if (ctx->currjob->funcargs == NULL) { if (ctx->currjob->funcargs == NULL) {
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE);
async_release_job(ctx->currjob); async_release_job(ctx->currjob);
ctx->currjob = NULL; ctx->currjob = NULL;
return ASYNC_ERR; return ASYNC_ERR;
@ -367,14 +362,12 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
return 0; return 0;
pool = OPENSSL_zalloc(sizeof(*pool)); pool = OPENSSL_zalloc(sizeof(*pool));
if (pool == NULL) { if (pool == NULL)
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
pool->jobs = sk_ASYNC_JOB_new_reserve(NULL, init_size); pool->jobs = sk_ASYNC_JOB_new_reserve(NULL, init_size);
if (pool->jobs == NULL) { if (pool->jobs == NULL) {
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_ASYNC, ERR_R_CRYPTO_LIB);
OPENSSL_free(pool); OPENSSL_free(pool);
return 0; return 0;
} }

View File

@ -47,10 +47,8 @@ int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,
{ {
struct fd_lookup_st *fdlookup; struct fd_lookup_st *fdlookup;
if ((fdlookup = OPENSSL_zalloc(sizeof(*fdlookup))) == NULL) { if ((fdlookup = OPENSSL_zalloc(sizeof(*fdlookup))) == NULL)
ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
fdlookup->key = key; fdlookup->key = key;
fdlookup->fd = fd; fdlookup->fd = fd;

View File

@ -291,7 +291,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
return 0; return 0;
p1 = OPENSSL_malloc((size_t)num); p1 = OPENSSL_malloc((size_t)num);
if (p1 == NULL) if (p1 == NULL)
goto malloc_error; return 0;
OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx->ibuf);
ctx->ibuf = p1; ctx->ibuf = p1;
} }
@ -322,14 +322,14 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
return 0; return 0;
p1 = OPENSSL_malloc((size_t)num); p1 = OPENSSL_malloc((size_t)num);
if (p1 == NULL) if (p1 == NULL)
goto malloc_error; return 0;
} }
if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
p2 = OPENSSL_malloc((size_t)num); p2 = OPENSSL_malloc((size_t)num);
if (p2 == NULL) { if (p2 == NULL) {
if (p1 != ctx->ibuf) if (p1 != ctx->ibuf)
OPENSSL_free(p1); OPENSSL_free(p1);
goto malloc_error; return 0;
} }
} }
if (ctx->ibuf != p1) { if (ctx->ibuf != p1) {
@ -405,9 +405,6 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
break; break;
} }
return ret; return ret;
malloc_error:
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0;
} }
static long buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) static long buffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)

View File

@ -57,13 +57,10 @@ static int linebuffer_new(BIO *bi)
{ {
BIO_LINEBUFFER_CTX *ctx; BIO_LINEBUFFER_CTX *ctx;
if ((ctx = OPENSSL_malloc(sizeof(*ctx))) == NULL) { if ((ctx = OPENSSL_malloc(sizeof(*ctx))) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ctx->obuf = OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); ctx->obuf = OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
if (ctx->obuf == NULL) { if (ctx->obuf == NULL) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
OPENSSL_free(ctx); OPENSSL_free(ctx);
return 0; return 0;
} }
@ -237,7 +234,7 @@ static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) { if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
p = OPENSSL_malloc((size_t)obs); p = OPENSSL_malloc((size_t)obs);
if (p == NULL) if (p == NULL)
goto malloc_error; return 0;
} }
if (ctx->obuf != p) { if (ctx->obuf != p) {
if (ctx->obuf_len > obs) { if (ctx->obuf_len > obs) {
@ -294,9 +291,6 @@ static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
break; break;
} }
return ret; return ret;
malloc_error:
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0;
} }
static long linebuffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) static long linebuffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)

View File

@ -55,10 +55,8 @@ static int nbiof_new(BIO *bi)
{ {
NBIO_TEST *nt; NBIO_TEST *nt;
if ((nt = OPENSSL_zalloc(sizeof(*nt))) == NULL) { if ((nt = OPENSSL_zalloc(sizeof(*nt))) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
nt->lrn = -1; nt->lrn = -1;
nt->lwn = -1; nt->lwn = -1;
bi->ptr = (char *)nt; bi->ptr = (char *)nt;

View File

@ -53,10 +53,8 @@ BIO_ADDR *BIO_ADDR_new(void)
{ {
BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret)); BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->sa.sa_family = AF_UNSPEC; ret->sa.sa_family = AF_UNSPEC;
return ret; return ret;
@ -279,7 +277,6 @@ static int addr_strings(const BIO_ADDR *ap, int numeric,
OPENSSL_free(*service); OPENSSL_free(*service);
*service = NULL; *service = NULL;
} }
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
@ -550,7 +547,7 @@ int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
} else { } else {
*host = OPENSSL_strndup(h, hl); *host = OPENSSL_strndup(h, hl);
if (*host == NULL) if (*host == NULL)
goto memerr; return 0;
} }
} }
if (p != NULL && service != NULL) { if (p != NULL && service != NULL) {
@ -560,7 +557,7 @@ int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
} else { } else {
*service = OPENSSL_strndup(p, pl); *service = OPENSSL_strndup(p, pl);
if (*service == NULL) if (*service == NULL)
goto memerr; return 0;
} }
} }
@ -571,9 +568,6 @@ int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
spec_err: spec_err:
ERR_raise(ERR_LIB_BIO, BIO_R_MALFORMED_HOST_OR_SERVICE); ERR_raise(ERR_LIB_BIO, BIO_R_MALFORMED_HOST_OR_SERVICE);
return 0; return 0;
memerr:
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0;
} }
/* addrinfo_wrap is used to build our own addrinfo "chain". /* addrinfo_wrap is used to build our own addrinfo "chain".
@ -590,10 +584,8 @@ static int addrinfo_wrap(int family, int socktype,
unsigned short port, unsigned short port,
BIO_ADDRINFO **bai) BIO_ADDRINFO **bai)
{ {
if ((*bai = OPENSSL_zalloc(sizeof(**bai))) == NULL) { if ((*bai = OPENSSL_zalloc(sizeof(**bai))) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
(*bai)->bai_family = family; (*bai)->bai_family = family;
(*bai)->bai_socktype = socktype; (*bai)->bai_socktype = socktype;
@ -688,7 +680,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
if (addrinfo_wrap(family, socktype, host, strlen(host), 0, res)) if (addrinfo_wrap(family, socktype, host, strlen(host), 0, res))
return 1; return 1;
else else
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BIO, ERR_R_BIO_LIB);
return 0; return 0;
} }
#endif #endif
@ -732,7 +724,8 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
# endif # endif
# ifdef EAI_MEMORY # ifdef EAI_MEMORY
case EAI_MEMORY: case EAI_MEMORY:
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); ERR_raise_data(ERR_LIB_BIO, ERR_R_SYS_LIB,
gai_strerror(old_ret ? old_ret : gai_ret));
break; break;
# endif # endif
case 0: case 0:
@ -789,7 +782,8 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
#endif #endif
if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) { if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); /* Should this be raised inside do_bio_lookup_init()? */
ERR_raise(ERR_LIB_BIO, ERR_R_CRYPTO_LIB);
ret = 0; ret = 0;
goto err; goto err;
} }
@ -927,14 +921,14 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
if (!addrinfo_wrap(he->h_addrtype, socktype, if (!addrinfo_wrap(he->h_addrtype, socktype,
*addrlistp, he->h_length, *addrlistp, he->h_length,
se->s_port, &tmp_bai)) se->s_port, &tmp_bai))
goto addrinfo_malloc_err; goto addrinfo_wrap_err;
tmp_bai->bai_next = *res; tmp_bai->bai_next = *res;
*res = tmp_bai; *res = tmp_bai;
continue; continue;
addrinfo_malloc_err: addrinfo_wrap_err:
BIO_ADDRINFO_free(*res); BIO_ADDRINFO_free(*res);
*res = NULL; *res = NULL;
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BIO, ERR_R_BIO_LIB);
ret = 0; ret = 0;
goto err; goto err;
} }

View File

@ -82,10 +82,8 @@ BIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *method)
{ {
BIO *bio = OPENSSL_zalloc(sizeof(*bio)); BIO *bio = OPENSSL_zalloc(sizeof(*bio));
if (bio == NULL) { if (bio == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
bio->libctx = libctx; bio->libctx = libctx;
bio->method = method; bio->method = method;
@ -97,7 +95,7 @@ BIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *method)
bio->lock = CRYPTO_THREAD_lock_new(); bio->lock = CRYPTO_THREAD_lock_new();
if (bio->lock == NULL) { if (bio->lock == NULL) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BIO, ERR_R_CRYPTO_LIB);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
goto err; goto err;
} }

View File

@ -25,7 +25,8 @@ int BIO_get_new_index(void)
int newval; int newval;
if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) { if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); /* Perhaps the error should be raised in do_bio_type_init()? */
ERR_raise(ERR_LIB_BIO, ERR_R_CRYPTO_LIB);
return -1; return -1;
} }
if (!CRYPTO_UP_REF(&bio_count, &newval, bio_type_lock)) if (!CRYPTO_UP_REF(&bio_count, &newval, bio_type_lock))
@ -40,7 +41,6 @@ BIO_METHOD *BIO_meth_new(int type, const char *name)
if (biom == NULL if (biom == NULL
|| (biom->name = OPENSSL_strdup(name)) == NULL) { || (biom->name = OPENSSL_strdup(name)) == NULL) {
OPENSSL_free(biom); OPENSSL_free(biom);
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
biom->type = type; biom->type = type;

View File

@ -847,10 +847,8 @@ doapr_outch(char **sbuffer,
*maxlen += BUFFER_INC; *maxlen += BUFFER_INC;
if (*buffer == NULL) { if (*buffer == NULL) {
if ((*buffer = OPENSSL_malloc(*maxlen)) == NULL) { if ((*buffer = OPENSSL_malloc(*maxlen)) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
if (*currlen > 0) { if (*currlen > 0) {
if (!ossl_assert(*sbuffer != NULL)) if (!ossl_assert(*sbuffer != NULL))
return 0; return 0;
@ -861,10 +859,8 @@ doapr_outch(char **sbuffer,
char *tmpbuf; char *tmpbuf;
tmpbuf = OPENSSL_realloc(*buffer, *maxlen); tmpbuf = OPENSSL_realloc(*buffer, *maxlen);
if (tmpbuf == NULL) { if (tmpbuf == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
*buffer = tmpbuf; *buffer = tmpbuf;
} }
} }

View File

@ -305,13 +305,14 @@ int BIO_accept(int sock, char **ip_port)
if (ip_port != NULL) { if (ip_port != NULL) {
char *host = BIO_ADDR_hostname_string(&res, 1); char *host = BIO_ADDR_hostname_string(&res, 1);
char *port = BIO_ADDR_service_string(&res, 1); char *port = BIO_ADDR_service_string(&res, 1);
if (host != NULL && port != NULL) if (host != NULL && port != NULL) {
*ip_port = OPENSSL_zalloc(strlen(host) + strlen(port) + 2); *ip_port = OPENSSL_zalloc(strlen(host) + strlen(port) + 2);
else } else {
*ip_port = NULL; *ip_port = NULL;
ERR_raise(ERR_LIB_BIO, ERR_R_BIO_LIB);
}
if (*ip_port == NULL) { if (*ip_port == NULL) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
BIO_closesocket(ret); BIO_closesocket(ret);
ret = (int)INVALID_SOCKET; ret = (int)INVALID_SOCKET;
} else { } else {

View File

@ -92,10 +92,8 @@ static BIO_ACCEPT *BIO_ACCEPT_new(void)
{ {
BIO_ACCEPT *ret; BIO_ACCEPT *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->accept_family = BIO_FAMILY_IPANY; ret->accept_family = BIO_FAMILY_IPANY;
ret->accept_sock = (int)INVALID_SOCKET; ret->accept_sock = (int)INVALID_SOCKET;
return ret; return ret;

View File

@ -620,20 +620,16 @@ static int bio_make_pair(BIO *bio1, BIO *bio2)
if (b1->buf == NULL) { if (b1->buf == NULL) {
b1->buf = OPENSSL_malloc(b1->size); b1->buf = OPENSSL_malloc(b1->size);
if (b1->buf == NULL) { if (b1->buf == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
b1->len = 0; b1->len = 0;
b1->offset = 0; b1->offset = 0;
} }
if (b2->buf == NULL) { if (b2->buf == NULL) {
b2->buf = OPENSSL_malloc(b2->size); b2->buf = OPENSSL_malloc(b2->size);
if (b2->buf == NULL) { if (b2->buf == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
b2->len = 0; b2->len = 0;
b2->offset = 0; b2->offset = 0;
} }

View File

@ -256,10 +256,8 @@ BIO_CONNECT *BIO_CONNECT_new(void)
{ {
BIO_CONNECT *ret; BIO_CONNECT *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->state = BIO_CONN_S_BEFORE; ret->state = BIO_CONN_S_BEFORE;
ret->connect_family = BIO_FAMILY_IPANY; ret->connect_family = BIO_FAMILY_IPANY;
return ret; return ret;

View File

@ -1820,10 +1820,8 @@ static int dgram_sctp_new(BIO *bi)
bi->init = 0; bi->init = 0;
bi->num = 0; bi->num = 0;
if ((data = OPENSSL_zalloc(sizeof(*data))) == NULL) { if ((data = OPENSSL_zalloc(sizeof(*data))) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
# ifdef SCTP_PR_SCTP_NONE # ifdef SCTP_PR_SCTP_NONE
data->prinfo.pr_policy = SCTP_PR_SCTP_NONE; data->prinfo.pr_policy = SCTP_PR_SCTP_NONE;
# endif # endif
@ -2058,10 +2056,8 @@ static int dgram_sctp_read(BIO *b, char *out, int outl)
optlen = optlen =
(socklen_t) (sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); (socklen_t) (sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t));
authchunks = OPENSSL_malloc(optlen); authchunks = OPENSSL_malloc(optlen);
if (authchunks == NULL) { if (authchunks == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return -1; return -1;
}
memset(authchunks, 0, optlen); memset(authchunks, 0, optlen);
ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS,
authchunks, &optlen); authchunks, &optlen);

View File

@ -286,13 +286,13 @@ static int dgram_pair_ctrl_make_bio_pair(BIO *bio1, BIO *bio2)
if (b1->rbuf.len != b1->req_buf_len) if (b1->rbuf.len != b1->req_buf_len)
if (ring_buf_init(&b1->rbuf, b1->req_buf_len) == 0) { if (ring_buf_init(&b1->rbuf, b1->req_buf_len) == 0) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BIO, ERR_R_BIO_LIB);
return 0; return 0;
} }
if (b2->rbuf.len != b2->req_buf_len) if (b2->rbuf.len != b2->req_buf_len)
if (ring_buf_init(&b2->rbuf, b2->req_buf_len) == 0) { if (ring_buf_init(&b2->rbuf, b2->req_buf_len) == 0) {
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BIO, ERR_R_BIO_LIB);
ring_buf_destroy(&b1->rbuf); ring_buf_destroy(&b1->rbuf);
return 0; return 0;
} }

View File

@ -197,10 +197,8 @@ static int slg_write(BIO *b, const char *in, int inl)
if (inl < 0) if (inl < 0)
return 0; return 0;
if ((buf = OPENSSL_malloc(inl + 1)) == NULL) { if ((buf = OPENSSL_malloc(inl + 1)) == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
memcpy(buf, in, inl); memcpy(buf, in, inl);
buf[inl] = '\0'; buf[inl] = '\0';

View File

@ -326,10 +326,8 @@ static int mem_write(BIO *b, const char *in, int inl)
if (bbm->use_dgrams) { if (bbm->use_dgrams) {
struct buf_mem_dgram_st *dgram = OPENSSL_malloc(sizeof(*dgram)); struct buf_mem_dgram_st *dgram = OPENSSL_malloc(sizeof(*dgram));
if (dgram == NULL) { if (dgram == NULL)
ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
goto end; goto end;
}
dgram->dgram = bbm->buf->data + blen; dgram->dgram = bbm->buf->data + blen;
dgram->dgramlen = inl; dgram->dgramlen = inl;

View File

@ -33,14 +33,12 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
bn_check_top(mod); bn_check_top(mod);
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->lock = CRYPTO_THREAD_lock_new(); ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) { if (ret->lock == NULL) {
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BN, ERR_R_CRYPTO_LIB);
OPENSSL_free(ret); OPENSSL_free(ret);
return NULL; return NULL;
} }

View File

@ -23,10 +23,8 @@ char *BN_bn2hex(const BIGNUM *a)
if (BN_is_zero(a)) if (BN_is_zero(a))
return OPENSSL_strdup("0"); return OPENSSL_strdup("0");
buf = OPENSSL_malloc(a->top * BN_BYTES * 2 + 2); buf = OPENSSL_malloc(a->top * BN_BYTES * 2 + 2);
if (buf == NULL) { if (buf == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
p = buf; p = buf;
if (a->neg) if (a->neg)
*p++ = '-'; *p++ = '-';
@ -70,10 +68,8 @@ char *BN_bn2dec(const BIGNUM *a)
bn_data_num = num / BN_DEC_NUM + 1; bn_data_num = num / BN_DEC_NUM + 1;
bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG)); bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG));
buf = OPENSSL_malloc(tbytes); buf = OPENSSL_malloc(tbytes);
if (buf == NULL || bn_data == NULL) { if (buf == NULL || bn_data == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if ((t = BN_dup(a)) == NULL) if ((t = BN_dup(a)) == NULL)
goto err; goto err;

View File

@ -119,10 +119,8 @@ BN_CTX *BN_CTX_new_ex(OSSL_LIB_CTX *ctx)
{ {
BN_CTX *ret; BN_CTX *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
/* Initialise the structure */ /* Initialise the structure */
BN_POOL_init(&ret->pool); BN_POOL_init(&ret->pool);
BN_STACK_init(&ret->stack); BN_STACK_init(&ret->stack);
@ -268,10 +266,8 @@ static int BN_STACK_push(BN_STACK *st, unsigned int idx)
st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES; st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;
unsigned int *newitems; unsigned int *newitems;
if ((newitems = OPENSSL_malloc(sizeof(*newitems) * newsize)) == NULL) { if ((newitems = OPENSSL_malloc(sizeof(*newitems) * newsize)) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
if (st->depth) if (st->depth)
memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth); memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);
OPENSSL_free(st->indexes); OPENSSL_free(st->indexes);
@ -322,10 +318,8 @@ static BIGNUM *BN_POOL_get(BN_POOL *p, int flag)
if (p->used == p->size) { if (p->used == p->size) {
BN_POOL_ITEM *item; BN_POOL_ITEM *item;
if ((item = OPENSSL_malloc(sizeof(*item))) == NULL) { if ((item = OPENSSL_malloc(sizeof(*item))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
for (loop = 0, bn = item->vals; loop++ < BN_CTX_POOL_SIZE; bn++) { for (loop = 0, bn = item->vals; loop++ < BN_CTX_POOL_SIZE; bn++) {
bn_init(bn); bn_init(bn);
if ((flag & BN_FLG_SECURE) != 0) if ((flag & BN_FLG_SECURE) != 0)

View File

@ -522,7 +522,7 @@ BIGNUM *BN_mod_inverse(BIGNUM *in,
if (ctx == NULL) { if (ctx == NULL) {
ctx = new_ctx = BN_CTX_new_ex(NULL); ctx = new_ctx = BN_CTX_new_ex(NULL);
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BN, ERR_R_BN_LIB);
return NULL; return NULL;
} }
} }

View File

@ -474,10 +474,8 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
bn_check_top(p); bn_check_top(p);
arr = OPENSSL_malloc(sizeof(*arr) * max); arr = OPENSSL_malloc(sizeof(*arr) * max);
if (arr == NULL) { if (arr == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ret = BN_GF2m_poly2arr(p, arr, max); ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) { if (!ret || ret > max) {
ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH); ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
@ -536,10 +534,8 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
bn_check_top(p); bn_check_top(p);
arr = OPENSSL_malloc(sizeof(*arr) * max); arr = OPENSSL_malloc(sizeof(*arr) * max);
if (arr == NULL) { if (arr == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ret = BN_GF2m_poly2arr(p, arr, max); ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) { if (!ret || ret > max) {
ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH); ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
@ -915,10 +911,8 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
bn_check_top(p); bn_check_top(p);
arr = OPENSSL_malloc(sizeof(*arr) * max); arr = OPENSSL_malloc(sizeof(*arr) * max);
if (arr == NULL) { if (arr == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ret = BN_GF2m_poly2arr(p, arr, max); ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) { if (!ret || ret > max) {
ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH); ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
@ -979,10 +973,8 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
bn_check_top(p); bn_check_top(p);
arr = OPENSSL_malloc(sizeof(*arr) * max); arr = OPENSSL_malloc(sizeof(*arr) * max);
if (arr == NULL) { if (arr == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ret = BN_GF2m_poly2arr(p, arr, max); ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) { if (!ret || ret > max) {
ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH); ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);
@ -1115,10 +1107,8 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
bn_check_top(p); bn_check_top(p);
arr = OPENSSL_malloc(sizeof(*arr) * max); arr = OPENSSL_malloc(sizeof(*arr) * max);
if (arr == NULL) { if (arr == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
ret = BN_GF2m_poly2arr(p, arr, max); ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) { if (!ret || ret > max) {
ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH); ERR_raise(ERR_LIB_BN, BN_R_INVALID_LENGTH);

View File

@ -29,10 +29,8 @@ signed char *bn_compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
if (BN_is_zero(scalar)) { if (BN_is_zero(scalar)) {
r = OPENSSL_malloc(1); r = OPENSSL_malloc(1);
if (r == NULL) { if (r == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
r[0] = 0; r[0] = 0;
*ret_len = 1; *ret_len = 1;
return r; return r;
@ -62,10 +60,8 @@ signed char *bn_compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
* (*ret_len will be set to the actual length, i.e. at most * (*ret_len will be set to the actual length, i.e. at most
* BN_num_bits(scalar) + 1) * BN_num_bits(scalar) + 1)
*/ */
if (r == NULL) { if (r == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
window_val = scalar->d[0] & mask; window_val = scalar->d[0] & mask;
j = 0; j = 0;
while ((window_val != 0) || (j + w + 1 < len)) { /* if j+w+1 >= len, while ((window_val != 0) || (j + w + 1 < len)) { /* if j+w+1 >= len,
@ -188,7 +184,7 @@ void bn_set_static_words(BIGNUM *a, const BN_ULONG *words, int size)
int bn_set_words(BIGNUM *a, const BN_ULONG *words, int num_words) int bn_set_words(BIGNUM *a, const BN_ULONG *words, int num_words)
{ {
if (bn_wexpand(a, num_words) == NULL) { if (bn_wexpand(a, num_words) == NULL) {
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BN, ERR_R_BN_LIB);
return 0; return 0;
} }

View File

@ -244,10 +244,8 @@ BIGNUM *BN_new(void)
{ {
BIGNUM *ret; BIGNUM *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->flags = BN_FLG_MALLOCED; ret->flags = BN_FLG_MALLOCED;
bn_check_top(ret); bn_check_top(ret);
return ret; return ret;
@ -279,10 +277,8 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
a = OPENSSL_secure_zalloc(words * sizeof(*a)); a = OPENSSL_secure_zalloc(words * sizeof(*a));
else else
a = OPENSSL_zalloc(words * sizeof(*a)); a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) { if (a == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
assert(b->top <= words); assert(b->top <= words);
if (b->top > 0) if (b->top > 0)
@ -1044,10 +1040,8 @@ BN_GENCB *BN_GENCB_new(void)
{ {
BN_GENCB *ret; BN_GENCB *ret;
if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
return ret; return ret;
} }

View File

@ -58,10 +58,8 @@ int bn_mod_add_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
if (mtop > sizeof(storage) / sizeof(storage[0])) { if (mtop > sizeof(storage) / sizeof(storage[0])) {
tp = OPENSSL_malloc(mtop * sizeof(BN_ULONG)); tp = OPENSSL_malloc(mtop * sizeof(BN_ULONG));
if (tp == NULL) { if (tp == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
} }
ap = a->d != NULL ? a->d : tp; ap = a->d != NULL ? a->d : tp;

View File

@ -229,10 +229,8 @@ BN_MONT_CTX *BN_MONT_CTX_new(void)
{ {
BN_MONT_CTX *ret; BN_MONT_CTX *ret;
if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
BN_MONT_CTX_init(ret); BN_MONT_CTX_init(ret);
ret->flags = BN_FLG_MALLOCED; ret->flags = BN_FLG_MALLOCED;

View File

@ -145,10 +145,8 @@ int BN_generate_prime_ex2(BIGNUM *ret, int bits, int safe,
} }
mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES); mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);
if (mods == NULL) { if (mods == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
BN_CTX_start(ctx); BN_CTX_start(ctx);
t = BN_CTX_get(ctx); t = BN_CTX_get(ctx);

View File

@ -41,10 +41,8 @@ static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom,
mask = 0xff << (bit + 1); mask = 0xff << (bit + 1);
buf = OPENSSL_malloc(bytes); buf = OPENSSL_malloc(bytes);
if (buf == NULL) { if (buf == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
/* make a random number and set the top and bottom bits */ /* make a random number and set the top and bottom bits */
b = flag == NORMAL ? RAND_bytes_ex(libctx, buf, bytes, strength) b = flag == NORMAL ? RAND_bytes_ex(libctx, buf, bytes, strength)

View File

@ -21,10 +21,8 @@ BN_RECP_CTX *BN_RECP_CTX_new(void)
{ {
BN_RECP_CTX *ret; BN_RECP_CTX *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_BN, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
bn_init(&(ret->N)); bn_init(&(ret->N));
bn_init(&(ret->Nr)); bn_init(&(ret->Nr));

View File

@ -33,10 +33,8 @@ BUF_MEM *BUF_MEM_new(void)
BUF_MEM *ret; BUF_MEM *ret;
ret = OPENSSL_zalloc(sizeof(*ret)); ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_BUF, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
return ret; return ret;
} }
@ -87,7 +85,7 @@ size_t BUF_MEM_grow(BUF_MEM *str, size_t len)
} }
/* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
if (len > LIMIT_BEFORE_EXPANSION) { if (len > LIMIT_BEFORE_EXPANSION) {
ERR_raise(ERR_LIB_BUF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BUF, ERR_R_PASSED_INVALID_ARGUMENT);
return 0; return 0;
} }
n = (len + 3) / 3 * 4; n = (len + 3) / 3 * 4;
@ -96,7 +94,6 @@ size_t BUF_MEM_grow(BUF_MEM *str, size_t len)
else else
ret = OPENSSL_realloc(str->data, n); ret = OPENSSL_realloc(str->data, n);
if (ret == NULL) { if (ret == NULL) {
ERR_raise(ERR_LIB_BUF, ERR_R_MALLOC_FAILURE);
len = 0; len = 0;
} else { } else {
str->data = ret; str->data = ret;
@ -125,7 +122,7 @@ size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
} }
/* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
if (len > LIMIT_BEFORE_EXPANSION) { if (len > LIMIT_BEFORE_EXPANSION) {
ERR_raise(ERR_LIB_BUF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_BUF, ERR_R_PASSED_INVALID_ARGUMENT);
return 0; return 0;
} }
n = (len + 3) / 3 * 4; n = (len + 3) / 3 * 4;
@ -134,7 +131,6 @@ size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
else else
ret = OPENSSL_clear_realloc(str->data, str->max, n); ret = OPENSSL_clear_realloc(str->data, str->max, n);
if (ret == NULL) { if (ret == NULL) {
ERR_raise(ERR_LIB_BUF, ERR_R_MALLOC_FAILURE);
len = 0; len = 0;
} else { } else {
str->data = ret; str->data = ret;

View File

@ -53,10 +53,8 @@ CMAC_CTX *CMAC_CTX_new(void)
{ {
CMAC_CTX *ctx; CMAC_CTX *ctx;
if ((ctx = OPENSSL_malloc(sizeof(*ctx))) == NULL) { if ((ctx = OPENSSL_malloc(sizeof(*ctx))) == NULL)
ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ctx->cctx = EVP_CIPHER_CTX_new(); ctx->cctx = EVP_CIPHER_CTX_new();
if (ctx->cctx == NULL) { if (ctx->cctx == NULL) {
OPENSSL_free(ctx); OPENSSL_free(ctx);

View File

@ -111,7 +111,7 @@ OSSL_CMP_CTX *OSSL_CMP_CTX_new(OSSL_LIB_CTX *libctx, const char *propq)
ctx->libctx = libctx; ctx->libctx = libctx;
if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL)
goto oom; goto err;
ctx->log_verbosity = OSSL_CMP_LOG_INFO; ctx->log_verbosity = OSSL_CMP_LOG_INFO;
@ -121,8 +121,10 @@ OSSL_CMP_CTX *OSSL_CMP_CTX_new(OSSL_LIB_CTX *libctx, const char *propq)
ctx->keep_alive = 1; ctx->keep_alive = 1;
ctx->msg_timeout = -1; ctx->msg_timeout = -1;
if ((ctx->untrusted = sk_X509_new_null()) == NULL) if ((ctx->untrusted = sk_X509_new_null()) == NULL) {
goto oom; ERR_raise(ERR_LIB_X509, ERR_R_CRYPTO_LIB);
goto err;
}
ctx->pbm_slen = 16; ctx->pbm_slen = 16;
if (!cmp_ctx_set_md(ctx, &ctx->pbm_owf, NID_sha256)) if (!cmp_ctx_set_md(ctx, &ctx->pbm_owf, NID_sha256))
@ -138,8 +140,6 @@ OSSL_CMP_CTX *OSSL_CMP_CTX_new(OSSL_LIB_CTX *libctx, const char *propq)
/* all other elements are initialized to 0 or NULL, respectively */ /* all other elements are initialized to 0 or NULL, respectively */
return ctx; return ctx;
oom:
ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
err: err:
OSSL_CMP_CTX_free(ctx); OSSL_CMP_CTX_free(ctx);
return NULL; return NULL;

View File

@ -1109,7 +1109,7 @@ OSSL_CMP_MSG *OSSL_CMP_MSG_read(const char *file, OSSL_LIB_CTX *libctx,
msg = OSSL_CMP_MSG_new(libctx, propq); msg = OSSL_CMP_MSG_new(libctx, propq);
if (msg == NULL) { if (msg == NULL) {
ERR_raise(ERR_LIB_CMP, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMP, ERR_R_CMP_LIB);
return NULL; return NULL;
} }

View File

@ -66,7 +66,7 @@ int ossl_cms_DigestedData_do_final(const CMS_ContentInfo *cms, BIO *chain,
CMS_DigestedData *dd; CMS_DigestedData *dd;
if (mctx == NULL) { if (mctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }

View File

@ -44,7 +44,7 @@ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
b = BIO_new(BIO_f_cipher()); b = BIO_new(BIO_f_cipher());
if (b == NULL) { if (b == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_BIO_LIB);
return NULL; return NULL;
} }
@ -116,10 +116,8 @@ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
/* Generate random session key */ /* Generate random session key */
if (!enc || !ec->key) { if (!enc || !ec->key) {
tkey = OPENSSL_malloc(tkeylen); tkey = OPENSSL_malloc(tkeylen);
if (tkey == NULL) { if (tkey == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0) if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0)
goto err; goto err;
} }
@ -163,7 +161,7 @@ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
if (enc) { if (enc) {
calg->parameter = ASN1_TYPE_new(); calg->parameter = ASN1_TYPE_new();
if (calg->parameter == NULL) { if (calg->parameter == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err; goto err;
} }
if ((EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { if ((EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) {
@ -206,10 +204,8 @@ int ossl_cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
{ {
ec->cipher = cipher; ec->cipher = cipher;
if (key) { if (key) {
if ((ec->key = OPENSSL_malloc(keylen)) == NULL) { if ((ec->key = OPENSSL_malloc(keylen)) == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
memcpy(ec->key, key, keylen); memcpy(ec->key, key, keylen);
} }
ec->keylen = keylen; ec->keylen = keylen;
@ -230,7 +226,7 @@ int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
if (ciph) { if (ciph) {
cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData); cms->d.encryptedData = M_ASN1_new_of(CMS_EncryptedData);
if (!cms->d.encryptedData) { if (!cms->d.encryptedData) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
return 0; return 0;
} }
cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted); cms->contentType = OBJ_nid2obj(NID_pkcs7_encrypted);

View File

@ -66,7 +66,7 @@ static CMS_EnvelopedData *cms_enveloped_data_init(CMS_ContentInfo *cms)
if (cms->d.other == NULL) { if (cms->d.other == NULL) {
cms->d.envelopedData = M_ASN1_new_of(CMS_EnvelopedData); cms->d.envelopedData = M_ASN1_new_of(CMS_EnvelopedData);
if (cms->d.envelopedData == NULL) { if (cms->d.envelopedData == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
return NULL; return NULL;
} }
cms->d.envelopedData->version = 0; cms->d.envelopedData->version = 0;
@ -85,7 +85,7 @@ cms_auth_enveloped_data_init(CMS_ContentInfo *cms)
if (cms->d.other == NULL) { if (cms->d.other == NULL) {
cms->d.authEnvelopedData = M_ASN1_new_of(CMS_AuthEnvelopedData); cms->d.authEnvelopedData = M_ASN1_new_of(CMS_AuthEnvelopedData);
if (cms->d.authEnvelopedData == NULL) { if (cms->d.authEnvelopedData == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
return NULL; return NULL;
} }
/* Defined in RFC 5083 - Section 2.1. "AuthEnvelopedData Type" */ /* Defined in RFC 5083 - Section 2.1. "AuthEnvelopedData Type" */
@ -222,18 +222,18 @@ CMS_ContentInfo *CMS_EnvelopedData_create_ex(const EVP_CIPHER *cipher,
cms = CMS_ContentInfo_new_ex(libctx, propq); cms = CMS_ContentInfo_new_ex(libctx, propq);
if (cms == NULL) if (cms == NULL)
goto merr; goto err;
env = cms_enveloped_data_init(cms); env = cms_enveloped_data_init(cms);
if (env == NULL) if (env == NULL)
goto merr; goto err;
if (!ossl_cms_EncryptedContent_init(env->encryptedContentInfo, cipher, NULL, if (!ossl_cms_EncryptedContent_init(env->encryptedContentInfo, cipher, NULL,
0, ossl_cms_get0_cmsctx(cms))) 0, ossl_cms_get0_cmsctx(cms)))
goto merr; goto err;
return cms; return cms;
merr: err:
CMS_ContentInfo_free(cms); CMS_ContentInfo_free(cms);
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
return NULL; return NULL;
} }
@ -299,7 +299,7 @@ CMS_AuthEnvelopedData_create_ex(const EVP_CIPHER *cipher, OSSL_LIB_CTX *libctx,
return cms; return cms;
merr: merr:
CMS_ContentInfo_free(cms); CMS_ContentInfo_free(cms);
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
return NULL; return NULL;
} }
@ -382,8 +382,10 @@ CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip,
/* Initialize recipient info */ /* Initialize recipient info */
ri = M_ASN1_new_of(CMS_RecipientInfo); ri = M_ASN1_new_of(CMS_RecipientInfo);
if (ri == NULL) if (ri == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
pk = X509_get0_pubkey(recip); pk = X509_get0_pubkey(recip);
if (pk == NULL) { if (pk == NULL) {
@ -410,13 +412,13 @@ CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip,
} }
if (!sk_CMS_RecipientInfo_push(ris, ri)) if (!sk_CMS_RecipientInfo_push(ris, ri)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
goto err;
}
return ri; return ri;
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
M_ASN1_free_of(ri, CMS_RecipientInfo); M_ASN1_free_of(ri, CMS_RecipientInfo);
return NULL; return NULL;
@ -527,11 +529,8 @@ static int cms_RecipientInfo_ktri_encrypt(const CMS_ContentInfo *cms,
goto err; goto err;
ek = OPENSSL_malloc(eklen); ek = OPENSSL_malloc(eklen);
if (ek == NULL)
if (ek == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (EVP_PKEY_encrypt(pctx, ek, &eklen, ec->key, ec->keylen) <= 0) if (EVP_PKEY_encrypt(pctx, ek, &eklen, ec->key, ec->keylen) <= 0)
goto err; goto err;
@ -614,10 +613,8 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
goto err; goto err;
ek = OPENSSL_malloc(eklen); ek = OPENSSL_malloc(eklen);
if (ek == NULL) { if (ek == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (EVP_PKEY_decrypt(ktri->pctx, ek, &eklen, if (EVP_PKEY_decrypt(ktri->pctx, ek, &eklen,
ktri->encryptedKey->data, ktri->encryptedKey->data,
@ -732,24 +729,32 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
/* Initialize recipient info */ /* Initialize recipient info */
ri = M_ASN1_new_of(CMS_RecipientInfo); ri = M_ASN1_new_of(CMS_RecipientInfo);
if (!ri) if (!ri) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
ri->d.kekri = M_ASN1_new_of(CMS_KEKRecipientInfo); ri->d.kekri = M_ASN1_new_of(CMS_KEKRecipientInfo);
if (!ri->d.kekri) if (!ri->d.kekri) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
ri->type = CMS_RECIPINFO_KEK; ri->type = CMS_RECIPINFO_KEK;
kekri = ri->d.kekri; kekri = ri->d.kekri;
if (otherTypeId) { if (otherTypeId) {
kekri->kekid->other = M_ASN1_new_of(CMS_OtherKeyAttribute); kekri->kekid->other = M_ASN1_new_of(CMS_OtherKeyAttribute);
if (kekri->kekid->other == NULL) if (kekri->kekid->other == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
} }
if (!sk_CMS_RecipientInfo_push(ris, ri)) if (!sk_CMS_RecipientInfo_push(ris, ri)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
goto err;
}
/* After this point no calls can fail */ /* After this point no calls can fail */
@ -772,8 +777,6 @@ CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
return ri; return ri;
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
M_ASN1_free_of(ri, CMS_RecipientInfo); M_ASN1_free_of(ri, CMS_RecipientInfo);
return NULL; return NULL;
@ -884,14 +887,12 @@ static int cms_RecipientInfo_kekri_encrypt(const CMS_ContentInfo *cms,
/* 8 byte prefix for AES wrap ciphers */ /* 8 byte prefix for AES wrap ciphers */
wkey = OPENSSL_malloc(ec->keylen + 8); wkey = OPENSSL_malloc(ec->keylen + 8);
if (wkey == NULL) { if (wkey == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
ctx = EVP_CIPHER_CTX_new(); ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
@ -967,14 +968,12 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
} }
ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8); ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8);
if (ukey == NULL) { if (ukey == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
ctx = EVP_CIPHER_CTX_new(); ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
@ -1272,7 +1271,7 @@ int ossl_cms_EnvelopedData_final(CMS_ContentInfo *cms, BIO *chain)
env->unprotectedAttrs = sk_X509_ATTRIBUTE_new_null(); env->unprotectedAttrs = sk_X509_ATTRIBUTE_new_null();
if (env->unprotectedAttrs == NULL) { if (env->unprotectedAttrs == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
return 0; return 0;
} }

View File

@ -121,13 +121,17 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0_ex(
CMS_ReceiptRequest *rr; CMS_ReceiptRequest *rr;
rr = CMS_ReceiptRequest_new(); rr = CMS_ReceiptRequest_new();
if (rr == NULL) if (rr == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
if (id) if (id)
ASN1_STRING_set0(rr->signedContentIdentifier, id, idlen); ASN1_STRING_set0(rr->signedContentIdentifier, id, idlen);
else { else {
if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32)) if (!ASN1_STRING_set(rr->signedContentIdentifier, NULL, 32)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
if (RAND_bytes_ex(libctx, rr->signedContentIdentifier->data, 32, if (RAND_bytes_ex(libctx, rr->signedContentIdentifier->data, 32,
0) <= 0) 0) <= 0)
goto err; goto err;
@ -146,9 +150,6 @@ CMS_ReceiptRequest *CMS_ReceiptRequest_create0_ex(
return rr; return rr;
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
CMS_ReceiptRequest_free(rr); CMS_ReceiptRequest_free(rr);
return NULL; return NULL;
@ -169,19 +170,20 @@ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr)
int rrderlen, r = 0; int rrderlen, r = 0;
rrderlen = i2d_CMS_ReceiptRequest(rr, &rrder); rrderlen = i2d_CMS_ReceiptRequest(rr, &rrder);
if (rrderlen < 0) if (rrderlen < 0) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
if (!CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_receiptRequest, if (!CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_receiptRequest,
V_ASN1_SEQUENCE, rrder, rrderlen)) V_ASN1_SEQUENCE, rrder, rrderlen)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
r = 1; r = 1;
merr: err:
if (!r)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
OPENSSL_free(rrder); OPENSSL_free(rrder);
return r; return r;
@ -241,7 +243,7 @@ int ossl_cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src)
} }
if (!CMS_signed_add1_attr_by_NID(dest, NID_id_smime_aa_msgSigDigest, if (!CMS_signed_add1_attr_by_NID(dest, NID_id_smime_aa_msgSigDigest,
V_ASN1_OCTET_STRING, dig, diglen)) { V_ASN1_OCTET_STRING, dig, diglen)) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
return 0; return 0;
} }
return 1; return 1;

View File

@ -18,6 +18,7 @@
int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms)
{ {
ASN1_OCTET_STRING **pos; ASN1_OCTET_STRING **pos;
pos = CMS_get0_content(cms); pos = CMS_get0_content(cms);
if (pos == NULL) if (pos == NULL)
return 0; return 0;
@ -29,7 +30,7 @@ int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms)
*boundary = &(*pos)->data; *boundary = &(*pos)->data;
return 1; return 1;
} }
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
return 0; return 0;
} }

View File

@ -60,7 +60,6 @@ CMS_ContentInfo *CMS_ContentInfo_new_ex(OSSL_LIB_CTX *libctx, const char *propq)
if (ci->ctx.propq == NULL) { if (ci->ctx.propq == NULL) {
CMS_ContentInfo_free(ci); CMS_ContentInfo_free(ci);
ci = NULL; ci = NULL;
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
} }
} }
} }
@ -404,7 +403,7 @@ int CMS_set_detached(CMS_ContentInfo *cms, int detached)
(*pos)->flags |= ASN1_STRING_FLAG_CONT; (*pos)->flags |= ASN1_STRING_FLAG_CONT;
return 1; return 1;
} }
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
return 0; return 0;
} }
@ -702,18 +701,23 @@ int ossl_cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert)
{ {
CMS_IssuerAndSerialNumber *ias; CMS_IssuerAndSerialNumber *ias;
ias = M_ASN1_new_of(CMS_IssuerAndSerialNumber); ias = M_ASN1_new_of(CMS_IssuerAndSerialNumber);
if (!ias) if (!ias) {
ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err; goto err;
if (!X509_NAME_set(&ias->issuer, X509_get_issuer_name(cert))) }
if (!X509_NAME_set(&ias->issuer, X509_get_issuer_name(cert))) {
ERR_raise(ERR_LIB_CMS, ERR_R_X509_LIB);
goto err; goto err;
if (!ASN1_STRING_copy(ias->serialNumber, X509_get0_serialNumber(cert))) }
if (!ASN1_STRING_copy(ias->serialNumber, X509_get0_serialNumber(cert))) {
ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err; goto err;
}
M_ASN1_free_of(*pias, CMS_IssuerAndSerialNumber); M_ASN1_free_of(*pias, CMS_IssuerAndSerialNumber);
*pias = ias; *pias = ias;
return 1; return 1;
err: err:
M_ASN1_free_of(ias, CMS_IssuerAndSerialNumber); M_ASN1_free_of(ias, CMS_IssuerAndSerialNumber);
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
@ -728,7 +732,7 @@ int ossl_cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert)
} }
keyid = ASN1_STRING_dup(cert_keyid); keyid = ASN1_STRING_dup(cert_keyid);
if (!keyid) { if (!keyid) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
return 0; return 0;
} }
ASN1_OCTET_STRING_free(*pkeyid); ASN1_OCTET_STRING_free(*pkeyid);

View File

@ -82,11 +82,12 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
/* Setup algorithm identifier for cipher */ /* Setup algorithm identifier for cipher */
encalg = X509_ALGOR_new(); encalg = X509_ALGOR_new();
if (encalg == NULL) { if (encalg == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
} }
ctx = EVP_CIPHER_CTX_new(); ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
@ -110,7 +111,7 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
} }
encalg->parameter = ASN1_TYPE_new(); encalg->parameter = ASN1_TYPE_new();
if (!encalg->parameter) { if (!encalg->parameter) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err; goto err;
} }
if (EVP_CIPHER_param_to_asn1(ctx, encalg->parameter) <= 0) { if (EVP_CIPHER_param_to_asn1(ctx, encalg->parameter) <= 0) {
@ -126,12 +127,16 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
/* Initialize recipient info */ /* Initialize recipient info */
ri = M_ASN1_new_of(CMS_RecipientInfo); ri = M_ASN1_new_of(CMS_RecipientInfo);
if (ri == NULL) if (ri == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
ri->d.pwri = M_ASN1_new_of(CMS_PasswordRecipientInfo); ri->d.pwri = M_ASN1_new_of(CMS_PasswordRecipientInfo);
if (ri->d.pwri == NULL) if (ri->d.pwri == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
ri->type = CMS_RECIPINFO_PASS; ri->type = CMS_RECIPINFO_PASS;
pwri = ri->d.pwri; pwri = ri->d.pwri;
@ -139,17 +144,23 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
/* Since this is overwritten, free up empty structure already there */ /* Since this is overwritten, free up empty structure already there */
X509_ALGOR_free(pwri->keyEncryptionAlgorithm); X509_ALGOR_free(pwri->keyEncryptionAlgorithm);
pwri->keyEncryptionAlgorithm = X509_ALGOR_new(); pwri->keyEncryptionAlgorithm = X509_ALGOR_new();
if (pwri->keyEncryptionAlgorithm == NULL) if (pwri->keyEncryptionAlgorithm == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
pwri->keyEncryptionAlgorithm->algorithm = OBJ_nid2obj(wrap_nid); pwri->keyEncryptionAlgorithm->algorithm = OBJ_nid2obj(wrap_nid);
pwri->keyEncryptionAlgorithm->parameter = ASN1_TYPE_new(); pwri->keyEncryptionAlgorithm->parameter = ASN1_TYPE_new();
if (pwri->keyEncryptionAlgorithm->parameter == NULL) if (pwri->keyEncryptionAlgorithm->parameter == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
if (!ASN1_item_pack(encalg, ASN1_ITEM_rptr(X509_ALGOR), if (!ASN1_item_pack(encalg, ASN1_ITEM_rptr(X509_ALGOR),
&pwri->keyEncryptionAlgorithm->parameter-> &pwri->keyEncryptionAlgorithm->parameter->
value.sequence)) value.sequence)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
pwri->keyEncryptionAlgorithm->parameter->type = V_ASN1_SEQUENCE; pwri->keyEncryptionAlgorithm->parameter->type = V_ASN1_SEQUENCE;
X509_ALGOR_free(encalg); X509_ALGOR_free(encalg);
@ -165,13 +176,13 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
CMS_RecipientInfo_set0_password(ri, pass, passlen); CMS_RecipientInfo_set0_password(ri, pass, passlen);
pwri->version = 0; pwri->version = 0;
if (!sk_CMS_RecipientInfo_push(ris, ri)) if (!sk_CMS_RecipientInfo_push(ris, ri)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
goto err;
}
return ri; return ri;
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_CTX_free(ctx);
if (ri) if (ri)
@ -201,10 +212,8 @@ static int kek_unwrap_key(unsigned char *out, size_t *outlen,
/* Invalid size */ /* Invalid size */
return 0; return 0;
} }
if ((tmp = OPENSSL_malloc(inlen)) == NULL) { if ((tmp = OPENSSL_malloc(inlen)) == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
/* setup IV by decrypting last two blocks */ /* setup IV by decrypting last two blocks */
if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl, if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
in + inlen - 2 * blocklen, blocklen * 2) in + inlen - 2 * blocklen, blocklen * 2)
@ -335,7 +344,7 @@ int ossl_cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms,
kekctx = EVP_CIPHER_CTX_new(); kekctx = EVP_CIPHER_CTX_new();
if (kekctx == NULL) { if (kekctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
/* Fixup cipher based on AlgorithmIdentifier to set IV etc */ /* Fixup cipher based on AlgorithmIdentifier to set IV etc */
@ -376,11 +385,8 @@ int ossl_cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms,
pwri->encryptedKey->length = keylen; pwri->encryptedKey->length = keylen;
} else { } else {
key = OPENSSL_malloc(pwri->encryptedKey->length); key = OPENSSL_malloc(pwri->encryptedKey->length);
if (key == NULL)
if (key == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (!kek_unwrap_key(key, &keylen, if (!kek_unwrap_key(key, &keylen,
pwri->encryptedKey->data, pwri->encryptedKey->data,
pwri->encryptedKey->length, kekctx)) { pwri->encryptedKey->length, kekctx)) {

View File

@ -38,7 +38,7 @@ static CMS_SignedData *cms_signed_data_init(CMS_ContentInfo *cms)
if (cms->d.other == NULL) { if (cms->d.other == NULL) {
cms->d.signedData = M_ASN1_new_of(CMS_SignedData); cms->d.signedData = M_ASN1_new_of(CMS_SignedData);
if (!cms->d.signedData) { if (!cms->d.signedData) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
return NULL; return NULL;
} }
cms->d.signedData->version = 1; cms->d.signedData->version = 1;
@ -349,8 +349,10 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
if (!sd) if (!sd)
goto err; goto err;
si = M_ASN1_new_of(CMS_SignerInfo); si = M_ASN1_new_of(CMS_SignerInfo);
if (!si) if (!si) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
/* Call for side-effect of computing hash and caching extensions */ /* Call for side-effect of computing hash and caching extensions */
X509_check_purpose(signer, -1, -1); X509_check_purpose(signer, -1, -1);
@ -364,7 +366,7 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
si->pctx = NULL; si->pctx = NULL;
if (si->mctx == NULL) { if (si->mctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
@ -413,12 +415,15 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
} }
if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) { if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) {
if ((alg = X509_ALGOR_new()) == NULL) if ((alg = X509_ALGOR_new()) == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_ASN1_LIB);
goto err;
}
X509_ALGOR_set_md(alg, md); X509_ALGOR_set_md(alg, md);
if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) { if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) {
X509_ALGOR_free(alg); X509_ALGOR_free(alg);
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
goto err;
} }
} }
@ -431,8 +436,10 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
*/ */
if (!si->signedAttrs) { if (!si->signedAttrs) {
si->signedAttrs = sk_X509_ATTRIBUTE_new_null(); si->signedAttrs = sk_X509_ATTRIBUTE_new_null();
if (!si->signedAttrs) if (!si->signedAttrs) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
goto err;
}
} }
if (!(flags & CMS_NOSMIMECAP)) { if (!(flags & CMS_NOSMIMECAP)) {
@ -442,8 +449,10 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
if (i) if (i)
i = CMS_add_smimecap(si, smcap); i = CMS_add_smimecap(si, smcap);
sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free); sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
if (!i) if (!i) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
} }
if (flags & CMS_CADES) { if (flags & CMS_CADES) {
ESS_SIGNING_CERT *sc = NULL; ESS_SIGNING_CERT *sc = NULL;
@ -479,8 +488,10 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
if (!(flags & CMS_NOCERTS)) { if (!(flags & CMS_NOCERTS)) {
/* NB ignore -1 return for duplicate cert */ /* NB ignore -1 return for duplicate cert */
if (!CMS_add1_cert(cms, signer)) if (!CMS_add1_cert(cms, signer)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
} }
if (flags & CMS_KEY_PARAM) { if (flags & CMS_KEY_PARAM) {
@ -503,15 +514,15 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
} }
} }
if (!sd->signerInfos) if (sd->signerInfos == NULL)
sd->signerInfos = sk_CMS_SignerInfo_new_null(); sd->signerInfos = sk_CMS_SignerInfo_new_null();
if (!sd->signerInfos || !sk_CMS_SignerInfo_push(sd->signerInfos, si)) if (sd->signerInfos == NULL || !sk_CMS_SignerInfo_push(sd->signerInfos, si)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CRYPTO_LIB);
goto err;
}
return si; return si;
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
M_ASN1_free_of(si, CMS_SignerInfo); M_ASN1_free_of(si, CMS_SignerInfo);
return NULL; return NULL;
@ -546,21 +557,22 @@ static int cms_add1_signingTime(CMS_SignerInfo *si, ASN1_TIME *t)
else else
tt = X509_gmtime_adj(NULL, 0); tt = X509_gmtime_adj(NULL, 0);
if (tt == NULL) if (tt == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_X509_LIB);
goto err;
}
if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime, if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime,
tt->type, tt, -1) <= 0) tt->type, tt, -1) <= 0) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
r = 1; r = 1;
merr: err:
if (t == NULL) if (t == NULL)
ASN1_TIME_free(tt); ASN1_TIME_free(tt);
if (!r)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
return r; return r;
} }
@ -703,7 +715,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms); const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms);
if (mctx == NULL) { if (mctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
return 0; return 0;
} }
@ -751,10 +763,8 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
} }
siglen = EVP_PKEY_get_size(si->pkey); siglen = EVP_PKEY_get_size(si->pkey);
sig = OPENSSL_malloc(siglen); sig = OPENSSL_malloc(siglen);
if (sig == NULL) { if (sig == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (EVP_PKEY_sign(pctx, sig, &siglen, md, mdlen) <= 0) { if (EVP_PKEY_sign(pctx, sig, &siglen, md, mdlen) <= 0) {
OPENSSL_free(sig); OPENSSL_free(sig);
goto err; goto err;
@ -769,10 +779,8 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
goto err; goto err;
} }
sig = OPENSSL_malloc(EVP_PKEY_get_size(si->pkey)); sig = OPENSSL_malloc(EVP_PKEY_get_size(si->pkey));
if (sig == NULL) { if (sig == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey, if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey,
ossl_cms_ctx_get0_libctx(ctx), ossl_cms_ctx_get0_libctx(ctx),
ossl_cms_ctx_get0_propq(ctx))) { ossl_cms_ctx_get0_propq(ctx))) {
@ -909,7 +917,7 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
(void)ERR_pop_to_mark(); (void)ERR_pop_to_mark();
if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) { if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
mctx = si->mctx; mctx = si->mctx;
@ -982,7 +990,7 @@ int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
unsigned int mlen; unsigned int mlen;
if (mctx == NULL) { if (mctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
goto err; goto err;
} }
/* If we have any signed attributes look for messageDigest value */ /* If we have any signed attributes look for messageDigest value */

View File

@ -39,7 +39,7 @@ static int cms_copy_content(BIO *out, BIO *in, unsigned int flags)
tmpout = cms_get_text_bio(out, flags); tmpout = cms_get_text_bio(out, flags);
if (tmpout == NULL) { if (tmpout == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err; goto err;
} }
@ -271,7 +271,7 @@ static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,
ctx = X509_STORE_CTX_new_ex(ossl_cms_ctx_get0_libctx(cms_ctx), ctx = X509_STORE_CTX_new_ex(ossl_cms_ctx_get0_libctx(cms_ctx),
ossl_cms_ctx_get0_propq(cms_ctx)); ossl_cms_ctx_get0_propq(cms_ctx));
if (ctx == NULL) { if (ctx == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_X509_LIB);
goto err; goto err;
} }
CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL); CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);
@ -356,10 +356,8 @@ int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
if (cadesVerify) { if (cadesVerify) {
/* Certificate trust chain is required to check CAdES signature */ /* Certificate trust chain is required to check CAdES signature */
si_chains = OPENSSL_zalloc(scount * sizeof(si_chains[0])); si_chains = OPENSSL_zalloc(scount * sizeof(si_chains[0]));
if (si_chains == NULL) { if (si_chains == NULL)
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
} }
cms_certs = CMS_get1_certs(cms); cms_certs = CMS_get1_certs(cms);
if (!(flags & CMS_NOCRL)) if (!(flags & CMS_NOCRL))
@ -406,7 +404,7 @@ int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
len = BIO_get_mem_data(dcont, &ptr); len = BIO_get_mem_data(dcont, &ptr);
tmpin = (len == 0) ? dcont : BIO_new_mem_buf(ptr, len); tmpin = (len == 0) ? dcont : BIO_new_mem_buf(ptr, len);
if (tmpin == NULL) { if (tmpin == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_BIO_LIB);
goto err2; goto err2;
} }
} else { } else {
@ -423,7 +421,7 @@ int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
*/ */
tmpout = cms_get_text_bio(out, flags); tmpout = cms_get_text_bio(out, flags);
if (tmpout == NULL) { if (tmpout == NULL) {
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err; goto err;
} }
cmsbio = CMS_dataInit(cms, tmpout); cmsbio = CMS_dataInit(cms, tmpout);
@ -511,12 +509,16 @@ CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey,
int i; int i;
cms = CMS_ContentInfo_new_ex(libctx, propq); cms = CMS_ContentInfo_new_ex(libctx, propq);
if (cms == NULL || !CMS_SignedData_init(cms)) if (cms == NULL || !CMS_SignedData_init(cms)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
if (flags & CMS_ASCIICRLF if (flags & CMS_ASCIICRLF
&& !CMS_set1_eContentType(cms, && !CMS_set1_eContentType(cms,
OBJ_nid2obj(NID_id_ct_asciiTextWithCRLF))) OBJ_nid2obj(NID_id_ct_asciiTextWithCRLF))) {
ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err; goto err;
}
if (pkey != NULL && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) { if (pkey != NULL && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) {
ERR_raise(ERR_LIB_CMS, CMS_R_ADD_SIGNER_ERROR); ERR_raise(ERR_LIB_CMS, CMS_R_ADD_SIGNER_ERROR);
@ -526,8 +528,10 @@ CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey,
for (i = 0; i < sk_X509_num(certs); i++) { for (i = 0; i < sk_X509_num(certs); i++) {
X509 *x = sk_X509_value(certs, i); X509 *x = sk_X509_value(certs, i);
if (!CMS_add1_cert(cms, x)) if (!CMS_add1_cert(cms, x)) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
} }
if (!(flags & CMS_DETACHED)) if (!(flags & CMS_DETACHED))
@ -539,9 +543,6 @@ CMS_ContentInfo *CMS_sign_ex(X509 *signcert, EVP_PKEY *pkey,
else else
goto err; goto err;
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
CMS_ContentInfo_free(cms); CMS_ContentInfo_free(cms);
return NULL; return NULL;
@ -637,8 +638,10 @@ CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *data,
cms = (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) cms = (EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)
? CMS_AuthEnvelopedData_create_ex(cipher, libctx, propq) ? CMS_AuthEnvelopedData_create_ex(cipher, libctx, propq)
: CMS_EnvelopedData_create_ex(cipher, libctx, propq); : CMS_EnvelopedData_create_ex(cipher, libctx, propq);
if (cms == NULL) if (cms == NULL) {
goto merr; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
goto err;
}
for (i = 0; i < sk_X509_num(certs); i++) { for (i = 0; i < sk_X509_num(certs); i++) {
recip = sk_X509_value(certs, i); recip = sk_X509_value(certs, i);
if (!CMS_add1_recipient_cert(cms, recip, flags)) { if (!CMS_add1_recipient_cert(cms, recip, flags)) {
@ -654,10 +657,8 @@ CMS_ContentInfo *CMS_encrypt_ex(STACK_OF(X509) *certs, BIO *data,
|| CMS_final(cms, data, NULL, flags)) || CMS_final(cms, data, NULL, flags))
return cms; return cms;
else else
goto err; ERR_raise(ERR_LIB_CMS, ERR_R_CMS_LIB);
merr:
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
err: err:
CMS_ContentInfo_free(cms); CMS_ContentInfo_free(cms);
return NULL; return NULL;

View File

@ -321,10 +321,8 @@ static int bio_zlib_new(BIO *bi)
} }
# endif # endif
ctx = OPENSSL_zalloc(sizeof(*ctx)); ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx == NULL) { if (ctx == NULL)
ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE; ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE;
ctx->obufsize = ZLIB_DEFAULT_BUFSIZE; ctx->obufsize = ZLIB_DEFAULT_BUFSIZE;
ctx->zin.zalloc = Z_NULL; ctx->zin.zalloc = Z_NULL;
@ -376,10 +374,8 @@ static int bio_zlib_read(BIO *b, char *out, int outl)
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
if (!ctx->ibuf) { if (!ctx->ibuf) {
ctx->ibuf = OPENSSL_malloc(ctx->ibufsize); ctx->ibuf = OPENSSL_malloc(ctx->ibufsize);
if (ctx->ibuf == NULL) { if (ctx->ibuf == NULL)
ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
if ((ret = inflateInit(zin)) != Z_OK) { if ((ret = inflateInit(zin)) != Z_OK) {
ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_INFLATE_ERROR, ERR_raise_data(ERR_LIB_COMP, COMP_R_ZLIB_INFLATE_ERROR,
"zlib error: %s", zError(ret)); "zlib error: %s", zError(ret));
@ -441,10 +437,8 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
if (!ctx->obuf) { if (!ctx->obuf) {
ctx->obuf = OPENSSL_malloc(ctx->obufsize); ctx->obuf = OPENSSL_malloc(ctx->obufsize);
/* Need error here */ /* Need error here */
if (ctx->obuf == NULL) { if (ctx->obuf == NULL)
ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
ctx->optr = ctx->obuf; ctx->optr = ctx->obuf;
ctx->ocount = 0; ctx->ocount = 0;
if ((ret = deflateInit(zout, ctx->comp_level)) != Z_OK) { if ((ret = deflateInit(zout, ctx->comp_level)) != Z_OK) {

View File

@ -19,10 +19,8 @@ COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
{ {
COMP_CTX *ret; COMP_CTX *ret;
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) { if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
ERR_raise(ERR_LIB_COMP, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->meth = meth; ret->meth = meth;
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
OPENSSL_free(ret); OPENSSL_free(ret);

View File

@ -233,13 +233,11 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
} }
section = OPENSSL_strdup("default"); section = OPENSSL_strdup("default");
if (section == NULL) { if (section == NULL)
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (_CONF_new_data(conf) == 0) { if (_CONF_new_data(conf) == 0) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CONF_LIB);
goto err; goto err;
} }
@ -425,10 +423,8 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
goto err; goto err;
} else if (strcmp(p, "includedir") == 0) { } else if (strcmp(p, "includedir") == 0) {
OPENSSL_free(conf->includedir); OPENSSL_free(conf->includedir);
if ((conf->includedir = OPENSSL_strdup(pval)) == NULL) { if ((conf->includedir = OPENSSL_strdup(pval)) == NULL)
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
} }
/* /*
@ -458,7 +454,6 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
include_path = OPENSSL_malloc(newlen); include_path = OPENSSL_malloc(newlen);
if (include_path == NULL) { if (include_path == NULL) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
OPENSSL_free(include); OPENSSL_free(include);
goto err; goto err;
} }
@ -495,13 +490,13 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
/* push the currently processing BIO onto stack */ /* push the currently processing BIO onto stack */
if (biosk == NULL) { if (biosk == NULL) {
if ((biosk = sk_BIO_new_null()) == NULL) { if ((biosk = sk_BIO_new_null()) == NULL) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
BIO_free(next); BIO_free(next);
goto err; goto err;
} }
} }
if (!sk_BIO_push(biosk, in)) { if (!sk_BIO_push(biosk, in)) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
BIO_free(next); BIO_free(next);
goto err; goto err;
} }
@ -519,16 +514,12 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
start = eat_ws(conf, p); start = eat_ws(conf, p);
trim_ws(conf, start); trim_ws(conf, start);
if ((v = OPENSSL_malloc(sizeof(*v))) == NULL) { if ((v = OPENSSL_malloc(sizeof(*v))) == NULL)
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
v->name = OPENSSL_strdup(pname); v->name = OPENSSL_strdup(pname);
v->value = NULL; v->value = NULL;
if (v->name == NULL) { if (v->name == NULL)
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (!str_copy(conf, psection, &(v->value), start)) if (!str_copy(conf, psection, &(v->value), start))
goto err; goto err;
@ -544,7 +535,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
} else } else
tv = sv; tv = sv;
if (_CONF_add_string(conf, tv, v) == 0) { if (_CONF_add_string(conf, tv, v) == 0) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CONF_LIB);
goto err; goto err;
} }
v = NULL; v = NULL;
@ -757,7 +748,7 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
goto err; goto err;
} }
if (!BUF_MEM_grow_clean(buf, newsize)) { if (!BUF_MEM_grow_clean(buf, newsize)) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_BUF_LIB);
goto err; goto err;
} }
while (*p) while (*p)
@ -849,10 +840,8 @@ static BIO *get_next_file(const char *path, OPENSSL_DIR_CTX **dirctx)
newlen = pathlen + namelen + 2; newlen = pathlen + namelen + 2;
newpath = OPENSSL_zalloc(newlen); newpath = OPENSSL_zalloc(newlen);
if (newpath == NULL) { if (newpath == NULL)
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
break; break;
}
#ifdef OPENSSL_SYS_VMS #ifdef OPENSSL_SYS_VMS
/* /*
* If the given path isn't clear VMS syntax, * If the given path isn't clear VMS syntax,

View File

@ -188,7 +188,7 @@ CONF *NCONF_new_ex(OSSL_LIB_CTX *libctx, CONF_METHOD *meth)
ret = meth->create(meth); ret = meth->create(meth);
if (ret == NULL) { if (ret == NULL) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CONF_LIB);
return NULL; return NULL;
} }
ret->libctx = libctx; ret->libctx = libctx;

View File

@ -100,7 +100,7 @@ DEFINE_RUN_ONCE_STATIC(do_init_module_list_lock)
{ {
module_list_lock = CRYPTO_THREAD_lock_new(); module_list_lock = CRYPTO_THREAD_lock_new();
if (module_list_lock == NULL) { if (module_list_lock == NULL) {
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
return 0; return 0;
} }
@ -332,10 +332,8 @@ static CONF_MODULE *module_add(DSO *dso, const char *name,
supported_modules = sk_CONF_MODULE_new_null(); supported_modules = sk_CONF_MODULE_new_null();
if (supported_modules == NULL) if (supported_modules == NULL)
goto err; goto err;
if ((tmod = OPENSSL_zalloc(sizeof(*tmod))) == NULL) { if ((tmod = OPENSSL_zalloc(sizeof(*tmod))) == NULL)
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
tmod->dso = dso; tmod->dso = dso;
tmod->name = OPENSSL_strdup(name); tmod->name = OPENSSL_strdup(name);
@ -435,14 +433,14 @@ static int module_init(CONF_MODULE *pmod, const char *name, const char *value,
initialized_modules = sk_CONF_IMODULE_new_null(); initialized_modules = sk_CONF_IMODULE_new_null();
if (initialized_modules == NULL) { if (initialized_modules == NULL) {
CRYPTO_THREAD_unlock(module_list_lock); CRYPTO_THREAD_unlock(module_list_lock);
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
goto err; goto err;
} }
} }
if (!sk_CONF_IMODULE_push(initialized_modules, imod)) { if (!sk_CONF_IMODULE_push(initialized_modules, imod)) {
CRYPTO_THREAD_unlock(module_list_lock); CRYPTO_THREAD_unlock(module_list_lock);
ERR_raise(ERR_LIB_CONF, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CONF, ERR_R_CRYPTO_LIB);
goto err; goto err;
} }

View File

@ -193,7 +193,5 @@ char *ossl_algorithm_get1_first_name(const OSSL_ALGORITHM *algo)
first_name_len = first_name_end - algo->algorithm_names; first_name_len = first_name_end - algo->algorithm_names;
ret = OPENSSL_strndup(algo->algorithm_names, first_name_len); ret = OPENSSL_strndup(algo->algorithm_names, first_name_len);
if (ret == NULL)
ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
return ret; return ret;
} }

View File

@ -34,10 +34,8 @@ static int ct_base64_decode(const char *in, unsigned char **out)
outlen = (inlen / 4) * 3; outlen = (inlen / 4) * 3;
outbuf = OPENSSL_malloc(outlen); outbuf = OPENSSL_malloc(outlen);
if (outbuf == NULL) { if (outbuf == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen); outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);
if (outlen < 0) { if (outlen < 0) {
@ -71,7 +69,7 @@ SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,
int declen; int declen;
if (sct == NULL) { if (sct == NULL) {
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CT, ERR_R_CT_LIB);
return NULL; return NULL;
} }

View File

@ -62,9 +62,6 @@ static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void)
{ {
CTLOG_STORE_LOAD_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); CTLOG_STORE_LOAD_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
if (ctx == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return ctx; return ctx;
} }
@ -104,23 +101,19 @@ CTLOG_STORE *CTLOG_STORE_new_ex(OSSL_LIB_CTX *libctx, const char *propq)
{ {
CTLOG_STORE *ret = OPENSSL_zalloc(sizeof(*ret)); CTLOG_STORE *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->libctx = libctx; ret->libctx = libctx;
if (propq != NULL) { if (propq != NULL) {
ret->propq = OPENSSL_strdup(propq); ret->propq = OPENSSL_strdup(propq);
if (ret->propq == NULL) { if (ret->propq == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
} }
ret->logs = sk_CTLOG_new_null(); ret->logs = sk_CTLOG_new_null();
if (ret->logs == NULL) { if (ret->logs == NULL) {
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_CT, ERR_R_CRYPTO_LIB);
goto err; goto err;
} }
@ -196,7 +189,7 @@ static int ctlog_store_load_log(const char *log_name, int log_name_len,
tmp = OPENSSL_strndup(log_name, log_name_len); tmp = OPENSSL_strndup(log_name, log_name_len);
if (tmp == NULL) if (tmp == NULL)
goto mem_err; return -1;
ret = ctlog_new_from_conf(load_ctx->log_store, &ct_log, load_ctx->conf, tmp); ret = ctlog_new_from_conf(load_ctx->log_store, &ct_log, load_ctx->conf, tmp);
OPENSSL_free(tmp); OPENSSL_free(tmp);
@ -212,14 +205,11 @@ static int ctlog_store_load_log(const char *log_name, int log_name_len,
} }
if (!sk_CTLOG_push(load_ctx->log_store->logs, ct_log)) { if (!sk_CTLOG_push(load_ctx->log_store->logs, ct_log)) {
goto mem_err; CTLOG_free(ct_log);
ERR_raise(ERR_LIB_CT, ERR_R_CRYPTO_LIB);
return -1;
} }
return 1; return 1;
mem_err:
CTLOG_free(ct_log);
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return -1;
} }
int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file) int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file)
@ -269,25 +259,19 @@ CTLOG *CTLOG_new_ex(EVP_PKEY *public_key, const char *name, OSSL_LIB_CTX *libctx
{ {
CTLOG *ret = OPENSSL_zalloc(sizeof(*ret)); CTLOG *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->libctx = libctx; ret->libctx = libctx;
if (propq != NULL) { if (propq != NULL) {
ret->propq = OPENSSL_strdup(propq); ret->propq = OPENSSL_strdup(propq);
if (ret->propq == NULL) { if (ret->propq == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
} }
ret->name = OPENSSL_strdup(name); ret->name = OPENSSL_strdup(name);
if (ret->name == NULL) { if (ret->name == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
if (ct_v1_log_id_from_pkey(ret, public_key) != 1) if (ct_v1_log_id_from_pkey(ret, public_key) != 1)
goto err; goto err;

View File

@ -178,10 +178,8 @@ int i2o_SCT_signature(const SCT *sct, unsigned char **out)
*out += len; *out += len;
} else { } else {
pstart = p = OPENSSL_malloc(len); pstart = p = OPENSSL_malloc(len);
if (p == NULL) { if (p == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
*out = p; *out = p;
} }
@ -225,10 +223,8 @@ int i2o_SCT(const SCT *sct, unsigned char **out)
*out += len; *out += len;
} else { } else {
pstart = p = OPENSSL_malloc(len); pstart = p = OPENSSL_malloc(len);
if (p == NULL) { if (p == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
goto err; goto err;
}
*out = p; *out = p;
} }
@ -330,10 +326,8 @@ int i2o_SCT_LIST(const STACK_OF(SCT) *a, unsigned char **pp)
ERR_raise(ERR_LIB_CT, CT_R_SCT_LIST_INVALID); ERR_raise(ERR_LIB_CT, CT_R_SCT_LIST_INVALID);
return -1; return -1;
} }
if ((*pp = OPENSSL_malloc(len)) == NULL) { if ((*pp = OPENSSL_malloc(len)) == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return -1; return -1;
}
is_pp_new = 1; is_pp_new = 1;
} }
p = *pp + 2; p = *pp + 2;

View File

@ -31,16 +31,13 @@ CT_POLICY_EVAL_CTX *CT_POLICY_EVAL_CTX_new_ex(OSSL_LIB_CTX *libctx,
CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX)); CT_POLICY_EVAL_CTX *ctx = OPENSSL_zalloc(sizeof(CT_POLICY_EVAL_CTX));
OSSL_TIME now; OSSL_TIME now;
if (ctx == NULL) { if (ctx == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ctx->libctx = libctx; ctx->libctx = libctx;
if (propq != NULL) { if (propq != NULL) {
ctx->propq = OPENSSL_strdup(propq); ctx->propq = OPENSSL_strdup(propq);
if (ctx->propq == NULL) { if (ctx->propq == NULL) {
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
OPENSSL_free(ctx); OPENSSL_free(ctx);
return NULL; return NULL;
} }

View File

@ -23,10 +23,8 @@ SCT *SCT_new(void)
{ {
SCT *sct = OPENSSL_zalloc(sizeof(*sct)); SCT *sct = OPENSSL_zalloc(sizeof(*sct));
if (sct == NULL) { if (sct == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
sct->entry_type = CT_LOG_ENTRY_TYPE_NOT_SET; sct->entry_type = CT_LOG_ENTRY_TYPE_NOT_SET;
sct->version = SCT_VERSION_NOT_SET; sct->version = SCT_VERSION_NOT_SET;
@ -105,10 +103,8 @@ int SCT_set1_log_id(SCT *sct, const unsigned char *log_id, size_t log_id_len)
if (log_id != NULL && log_id_len > 0) { if (log_id != NULL && log_id_len > 0) {
sct->log_id = OPENSSL_memdup(log_id, log_id_len); sct->log_id = OPENSSL_memdup(log_id, log_id_len);
if (sct->log_id == NULL) { if (sct->log_id == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
sct->log_id_len = log_id_len; sct->log_id_len = log_id_len;
} }
return 1; return 1;
@ -157,10 +153,8 @@ int SCT_set1_extensions(SCT *sct, const unsigned char *ext, size_t ext_len)
if (ext != NULL && ext_len > 0) { if (ext != NULL && ext_len > 0) {
sct->ext = OPENSSL_memdup(ext, ext_len); sct->ext = OPENSSL_memdup(ext, ext_len);
if (sct->ext == NULL) { if (sct->ext == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
sct->ext_len = ext_len; sct->ext_len = ext_len;
} }
return 1; return 1;
@ -183,10 +177,8 @@ int SCT_set1_signature(SCT *sct, const unsigned char *sig, size_t sig_len)
if (sig != NULL && sig_len > 0) { if (sig != NULL && sig_len > 0) {
sct->sig = OPENSSL_memdup(sig, sig_len); sct->sig = OPENSSL_memdup(sig, sig_len);
if (sct->sig == NULL) { if (sct->sig == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
sct->sig_len = sig_len; sct->sig_len = sig_len;
} }
return 1; return 1;

View File

@ -24,16 +24,13 @@ SCT_CTX *SCT_CTX_new(OSSL_LIB_CTX *libctx, const char *propq)
{ {
SCT_CTX *sctx = OPENSSL_zalloc(sizeof(*sctx)); SCT_CTX *sctx = OPENSSL_zalloc(sizeof(*sctx));
if (sctx == NULL) { if (sctx == NULL)
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
sctx->libctx = libctx; sctx->libctx = libctx;
if (propq != NULL) { if (propq != NULL) {
sctx->propq = OPENSSL_strdup(propq); sctx->propq = OPENSSL_strdup(propq);
if (sctx->propq == NULL) { if (sctx->propq == NULL) {
ERR_raise(ERR_LIB_CT, ERR_R_MALLOC_FAILURE);
OPENSSL_free(sctx); OPENSSL_free(sctx);
return NULL; return NULL;
} }

View File

@ -121,12 +121,12 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
str = ASN1_STRING_new(); str = ASN1_STRING_new();
if (str == NULL) { if (str == NULL) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_ASN1_LIB);
goto err; goto err;
} }
str->length = i2d_dhp(pkey, dh, &str->data); str->length = i2d_dhp(pkey, dh, &str->data);
if (str->length <= 0) { if (str->length <= 0) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_ASN1_LIB);
goto err; goto err;
} }
ptype = V_ASN1_SEQUENCE; ptype = V_ASN1_SEQUENCE;
@ -140,7 +140,7 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
ASN1_INTEGER_free(pub_key); ASN1_INTEGER_free(pub_key);
if (penclen <= 0) { if (penclen <= 0) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -184,13 +184,13 @@ static int dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
params = ASN1_STRING_new(); params = ASN1_STRING_new();
if (params == NULL) { if (params == NULL) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_ASN1_LIB);
goto err; goto err;
} }
params->length = i2d_dhp(pkey, pkey->pkey.dh, &params->data); params->length = i2d_dhp(pkey, pkey->pkey.dh, &params->data);
if (params->length <= 0) { if (params->length <= 0) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_ASN1_LIB);
goto err; goto err;
} }
params->type = V_ASN1_SEQUENCE; params->type = V_ASN1_SEQUENCE;
@ -514,7 +514,7 @@ static int dh_pkey_import_from_type(const OSSL_PARAM params[], void *vpctx,
DH *dh = ossl_dh_new_ex(pctx->libctx); DH *dh = ossl_dh_new_ex(pctx->libctx);
if (dh == NULL) { if (dh == NULL) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_DH_LIB);
return 0; return 0;
} }
DH_clear_flags(dh, DH_FLAG_TYPE_MASK); DH_clear_flags(dh, DH_FLAG_TYPE_MASK);

View File

@ -1,6 +1,6 @@
/* /*
* Generated by util/mkerr.pl DO NOT EDIT * Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the Apache License 2.0 (the "License"). You may not use * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
@ -42,6 +42,7 @@ static const ERR_STRING_DATA DH_str_reasons[] = {
"invalid parameter nid"}, "invalid parameter nid"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_INVALID_PUBKEY), "invalid public key"}, {ERR_PACK(ERR_LIB_DH, 0, DH_R_INVALID_PUBKEY), "invalid public key"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_INVALID_SECRET), "invalid secret"}, {ERR_PACK(ERR_LIB_DH, 0, DH_R_INVALID_SECRET), "invalid secret"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_INVALID_SIZE), "invalid size"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_KDF_PARAMETER_ERROR), "kdf parameter error"}, {ERR_PACK(ERR_LIB_DH, 0, DH_R_KDF_PARAMETER_ERROR), "kdf parameter error"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_KEYS_NOT_SET), "keys not set"}, {ERR_PACK(ERR_LIB_DH, 0, DH_R_KEYS_NOT_SET), "keys not set"},
{ERR_PACK(ERR_LIB_DH, 0, DH_R_MISSING_PUBKEY), "missing pubkey"}, {ERR_PACK(ERR_LIB_DH, 0, DH_R_MISSING_PUBKEY), "missing pubkey"},

View File

@ -418,14 +418,15 @@ size_t ossl_dh_key2buf(const DH *dh, unsigned char **pbuf_out, size_t size,
if (!alloc) { if (!alloc) {
if (size >= (size_t)p_size) if (size >= (size_t)p_size)
pbuf = *pbuf_out; pbuf = *pbuf_out;
if (pbuf == NULL)
ERR_raise(ERR_LIB_DH, DH_R_INVALID_SIZE);
} else { } else {
pbuf = OPENSSL_malloc(p_size); pbuf = OPENSSL_malloc(p_size);
} }
if (pbuf == NULL) { /* Errors raised above */
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); if (pbuf == NULL)
return 0; return 0;
}
/* /*
* As per Section 4.2.8.1 of RFC 8446 left pad public * As per Section 4.2.8.1 of RFC 8446 left pad public
* key with zeros to the size of p * key with zeros to the size of p

View File

@ -75,15 +75,13 @@ static DH *dh_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx)
{ {
DH *ret = OPENSSL_zalloc(sizeof(*ret)); DH *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->references = 1; ret->references = 1;
ret->lock = CRYPTO_THREAD_lock_new(); ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) { if (ret->lock == NULL) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DH, ERR_R_CRYPTO_LIB);
OPENSSL_free(ret); OPENSSL_free(ret);
return NULL; return NULL;
} }

View File

@ -31,7 +31,6 @@ DH_METHOD *DH_meth_new(const char *name, int flags)
OPENSSL_free(dhm); OPENSSL_free(dhm);
} }
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
@ -57,7 +56,6 @@ DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
OPENSSL_free(ret); OPENSSL_free(ret);
} }
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
@ -70,10 +68,8 @@ int DH_meth_set1_name(DH_METHOD *dhm, const char *name)
{ {
char *tmpname = OPENSSL_strdup(name); char *tmpname = OPENSSL_strdup(name);
if (tmpname == NULL) { if (tmpname == NULL)
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
OPENSSL_free(dhm->name); OPENSSL_free(dhm->name);
dhm->name = tmpname; dhm->name = tmpname;

View File

@ -55,10 +55,8 @@ static int pkey_dh_init(EVP_PKEY_CTX *ctx)
{ {
DH_PKEY_CTX *dctx; DH_PKEY_CTX *dctx;
if ((dctx = OPENSSL_zalloc(sizeof(*dctx))) == NULL) { if ((dctx = OPENSSL_zalloc(sizeof(*dctx))) == NULL)
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
dctx->prime_len = 2048; dctx->prime_len = 2048;
dctx->subprime_len = -1; dctx->subprime_len = -1;
dctx->generator = 2; dctx->generator = 2;
@ -445,10 +443,8 @@ static int pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key,
ret = 0; ret = 0;
if ((Zlen = DH_size(dh)) <= 0) if ((Zlen = DH_size(dh)) <= 0)
return 0; return 0;
if ((Z = OPENSSL_malloc(Zlen)) == NULL) { if ((Z = OPENSSL_malloc(Zlen)) == NULL)
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return 0; return 0;
}
if (DH_compute_key_padded(Z, dhpubbn, dh) <= 0) if (DH_compute_key_padded(Z, dhpubbn, dh) <= 0)
goto err; goto err;
if (!DH_KDF_X9_42(key, *keylen, Z, Zlen, dctx->kdf_oid, if (!DH_KDF_X9_42(key, *keylen, Z, Zlen, dctx->kdf_oid,

View File

@ -54,7 +54,7 @@ static int dsa_pub_decode(EVP_PKEY *pkey, const X509_PUBKEY *pubkey)
} else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF)) { } else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF)) {
if ((dsa = DSA_new()) == NULL) { if ((dsa = DSA_new()) == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_DSA_LIB);
goto err; goto err;
} }
} else { } else {
@ -101,12 +101,12 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
&& dsa->params.g != NULL) { && dsa->params.g != NULL) {
str = ASN1_STRING_new(); str = ASN1_STRING_new();
if (str == NULL) { if (str == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_ASN1_LIB);
goto err; goto err;
} }
str->length = i2d_DSAparams(dsa, &str->data); str->length = i2d_DSAparams(dsa, &str->data);
if (str->length <= 0) { if (str->length <= 0) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_ASN1_LIB);
goto err; goto err;
} }
ptype = V_ASN1_SEQUENCE; ptype = V_ASN1_SEQUENCE;
@ -116,7 +116,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL); pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL);
if (pubint == NULL) { if (pubint == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -124,7 +124,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
ASN1_INTEGER_free(pubint); ASN1_INTEGER_free(pubint);
if (penclen <= 0) { if (penclen <= 0) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_ASN1_LIB);
goto err; goto err;
} }
@ -175,13 +175,13 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
params = ASN1_STRING_new(); params = ASN1_STRING_new();
if (params == NULL) { if (params == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_ASN1_LIB);
goto err; goto err;
} }
params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data); params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);
if (params->length <= 0) { if (params->length <= 0) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_ASN1_LIB);
goto err; goto err;
} }
params->type = V_ASN1_SEQUENCE; params->type = V_ASN1_SEQUENCE;
@ -483,7 +483,7 @@ static int dsa_pkey_import_from(const OSSL_PARAM params[], void *vpctx)
DSA *dsa = ossl_dsa_new(pctx->libctx); DSA *dsa = ossl_dsa_new(pctx->libctx);
if (dsa == NULL) { if (dsa == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_DSA_LIB);
return 0; return 0;
} }

View File

@ -158,11 +158,11 @@ DSA *ossl_dsa_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
} }
/* Calculate public key */ /* Calculate public key */
if ((dsa_pubkey = BN_new()) == NULL) { if ((dsa_pubkey = BN_new()) == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_BN_LIB);
goto dsaerr; goto dsaerr;
} }
if ((ctx = BN_CTX_new()) == NULL) { if ((ctx = BN_CTX_new()) == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_BN_LIB);
goto dsaerr; goto dsaerr;
} }

View File

@ -134,15 +134,13 @@ static DSA *dsa_new_intern(ENGINE *engine, OSSL_LIB_CTX *libctx)
{ {
DSA *ret = OPENSSL_zalloc(sizeof(*ret)); DSA *ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) { if (ret == NULL)
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
}
ret->references = 1; ret->references = 1;
ret->lock = CRYPTO_THREAD_lock_new(); ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) { if (ret->lock == NULL) {
ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); ERR_raise(ERR_LIB_DSA, ERR_R_CRYPTO_LIB);
OPENSSL_free(ret); OPENSSL_free(ret);
return NULL; return NULL;
} }

Some files were not shown because too many files have changed in this diff Show More