summaryrefslogtreecommitdiff
path: root/crypto/asn1
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2022-09-29 13:57:34 +0200
committerRichard Levitte <levitte@openssl.org>2022-10-05 14:02:03 +0200
commite077455e9e57ed4ee4676996b4a9aa11df6327a6 (patch)
treeedcb7412024f95fbc97c2c7a780f78ad05d586e3 /crypto/asn1
parent9167a47f78159b0578bc032401ab1d66e14eecdb (diff)
downloadopenssl-new-e077455e9e57ed4ee4676996b4a9aa11df6327a6.tar.gz
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)
Diffstat (limited to 'crypto/asn1')
-rw-r--r--crypto/asn1/a_bitstr.c10
-rw-r--r--crypto/asn1/a_d2i_fp.c6
-rw-r--r--crypto/asn1/a_digest.c4
-rw-r--r--crypto/asn1/a_dup.c6
-rw-r--r--crypto/asn1/a_i2d_fp.c6
-rw-r--r--crypto/asn1/a_int.c16
-rw-r--r--crypto/asn1/a_mbstr.c5
-rw-r--r--crypto/asn1/a_object.c20
-rw-r--r--crypto/asn1/a_sign.c6
-rw-r--r--crypto/asn1/a_strex.c4
-rw-r--r--crypto/asn1/a_strnid.c6
-rw-r--r--crypto/asn1/a_time.c4
-rw-r--r--crypto/asn1/a_verify.c8
-rw-r--r--crypto/asn1/ameth_lib.c5
-rw-r--r--crypto/asn1/asn1_gen.c12
-rw-r--r--crypto/asn1/asn1_lib.c5
-rw-r--r--crypto/asn1/asn_mime.c8
-rw-r--r--crypto/asn1/asn_moid.c4
-rw-r--r--crypto/asn1/asn_mstbl.c2
-rw-r--r--crypto/asn1/asn_pack.c4
-rw-r--r--crypto/asn1/bio_asn1.c10
-rw-r--r--crypto/asn1/bio_ndef.c8
-rw-r--r--crypto/asn1/f_int.c1
-rw-r--r--crypto/asn1/f_string.c1
-rw-r--r--crypto/asn1/p5_pbe.c13
-rw-r--r--crypto/asn1/p5_pbev2.c107
-rw-r--r--crypto/asn1/p5_scrypt.c95
-rw-r--r--crypto/asn1/tasn_dec.c12
-rw-r--r--crypto/asn1/tasn_enc.c12
-rw-r--r--crypto/asn1/tasn_new.c30
-rw-r--r--crypto/asn1/tasn_prn.c4
-rw-r--r--crypto/asn1/tasn_scn.c4
-rw-r--r--crypto/asn1/tasn_utl.c6
-rw-r--r--crypto/asn1/x_info.c4
-rw-r--r--crypto/asn1/x_int64.c8
-rw-r--r--crypto/asn1/x_pkey.c13
36 files changed, 229 insertions, 240 deletions
diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c
index 7b3991a071..00a388a3a5 100644
--- a/crypto/asn1/a_bitstr.c
+++ b/crypto/asn1/a_bitstr.c
@@ -82,7 +82,7 @@ ASN1_BIT_STRING *ossl_c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
ASN1_BIT_STRING *ret = NULL;
const unsigned char *p;
unsigned char *s;
- int i;
+ int i = 0;
if (len < 1) {
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 */
s = OPENSSL_malloc((int)len);
if (s == NULL) {
- i = ERR_R_MALLOC_FAILURE;
goto err;
}
memcpy(s, p, (int)len);
@@ -131,7 +130,8 @@ ASN1_BIT_STRING *ossl_c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
*pp = p;
return ret;
err:
- ERR_raise(ERR_LIB_ASN1, i);
+ if (i != 0)
+ ERR_raise(ERR_LIB_ASN1, i);
if ((a == NULL) || (*a != ret))
ASN1_BIT_STRING_free(ret);
return NULL;
@@ -160,10 +160,8 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
if (!value)
return 1; /* Don't need to set */
c = OPENSSL_clear_realloc(a->data, a->length, w + 1);
- if (c == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (c == NULL)
return 0;
- }
if (w + 1 - a->length > 0)
memset(c + a->length, 0, w + 1 - a->length);
a->data = c;
diff --git a/crypto/asn1/a_d2i_fp.c b/crypto/asn1/a_d2i_fp.c
index e8602053f9..4af2276a8d 100644
--- a/crypto/asn1/a_d2i_fp.c
+++ b/crypto/asn1/a_d2i_fp.c
@@ -123,7 +123,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
b = BUF_MEM_new();
if (b == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
return -1;
}
@@ -134,7 +134,7 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
want -= diff;
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;
}
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;
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;
}
want -= chunk;
diff --git a/crypto/asn1/a_digest.c b/crypto/asn1/a_digest.c
index 72cc880779..67e8a96ba1 100644
--- a/crypto/asn1/a_digest.c
+++ b/crypto/asn1/a_digest.c
@@ -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);
return 0;
}
- if ((str = OPENSSL_malloc(inl)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((str = OPENSSL_malloc(inl)) == NULL)
return 0;
- }
p = str;
i2d(data, &p);
diff --git a/crypto/asn1/a_dup.c b/crypto/asn1/a_dup.c
index 93e8b2aa8d..23d1d63808 100644
--- a/crypto/asn1/a_dup.c
+++ b/crypto/asn1/a_dup.c
@@ -28,10 +28,8 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x)
return NULL;
b = OPENSSL_malloc(i + 10);
- if (b == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (b == NULL)
return NULL;
- }
p = b;
i = i2d(x, &p);
p2 = b;
@@ -78,7 +76,7 @@ void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)
i = ASN1_item_i2d(x, &b, it);
if (b == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return NULL;
}
p = b;
diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c
index 4cc4773666..e30f1f2a17 100644
--- a/crypto/asn1/a_i2d_fp.c
+++ b/crypto/asn1/a_i2d_fp.c
@@ -42,10 +42,8 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x)
return 0;
b = OPENSSL_malloc(n);
- if (b == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (b == NULL)
return 0;
- }
p = (unsigned char *)b;
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);
if (b == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0;
}
diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c
index c3ab6a9222..dc962290dd 100644
--- a/crypto/asn1/a_int.c
+++ b/crypto/asn1/a_int.c
@@ -303,8 +303,10 @@ ASN1_INTEGER *ossl_c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
} else
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;
+ }
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;
return ret;
err:
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
if (a == NULL || *a != ret)
ASN1_INTEGER_free(ret);
return NULL;
@@ -400,7 +401,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
unsigned char *s;
long len = 0;
int inf, tag, xclass;
- int i;
+ int i = 0;
if ((a == NULL) || ((*a) == 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.
*/
s = OPENSSL_malloc((int)len + 1);
- if (s == NULL) {
- i = ERR_R_MALLOC_FAILURE;
+ if (s == NULL)
goto err;
- }
ret->type = V_ASN1_INTEGER;
if (len) {
if ((*p == 0) && (len != 1)) {
@@ -450,7 +449,8 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
*pp = p;
return ret;
err:
- ERR_raise(ERR_LIB_ASN1, i);
+ if (i != 0)
+ ERR_raise(ERR_LIB_ASN1, i);
if ((a == NULL) || (*a != ret))
ASN1_INTEGER_free(ret);
return NULL;
@@ -483,7 +483,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
len = 1;
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;
}
diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c
index be2d5aa68f..7d80798655 100644
--- a/crypto/asn1/a_mbstr.c
+++ b/crypto/asn1/a_mbstr.c
@@ -145,7 +145,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
free_out = 1;
dest = ASN1_STRING_type_new(str_type);
if (dest == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return -1;
}
*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 (inform == outform) {
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 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 (free_out)
ASN1_STRING_free(dest);
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return -1;
}
dest->length = outlen;
diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c
index c96c36e730..73c69eacd2 100644
--- a/crypto/asn1/a_object.c
+++ b/crypto/asn1/a_object.c
@@ -31,10 +31,8 @@ int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
return objsize;
if (*pp == NULL) {
- if ((p = allocated = OPENSSL_malloc(objsize)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((p = allocated = OPENSSL_malloc(objsize)) == NULL)
return 0;
- }
} else {
p = *pp;
}
@@ -135,10 +133,8 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
OPENSSL_free(tmp);
tmpsize = blsize + 32;
tmp = OPENSSL_malloc(tmpsize);
- if (tmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (tmp == NULL)
goto err;
- }
}
while (blsize--) {
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);
return -1;
}
- if ((p = OPENSSL_malloc(i + 1)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((p = OPENSSL_malloc(i + 1)) == NULL)
return -1;
- }
i2t_ASN1_OBJECT(p, i + 1, a);
}
if (i <= 0) {
@@ -308,10 +302,8 @@ ASN1_OBJECT *ossl_c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
ret->length = 0;
OPENSSL_free(data);
data = OPENSSL_malloc(length);
- if (data == NULL) {
- i = ERR_R_MALLOC_FAILURE;
+ if (data == NULL)
goto err;
- }
ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
}
memcpy(data, p, length);
@@ -345,10 +337,8 @@ ASN1_OBJECT *ASN1_OBJECT_new(void)
ASN1_OBJECT *ret;
ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
return ret;
}
diff --git a/crypto/asn1/a_sign.c b/crypto/asn1/a_sign.c
index a1e2719e64..8507fc3668 100644
--- a/crypto/asn1/a_sign.c
+++ b/crypto/asn1/a_sign.c
@@ -35,7 +35,7 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
X509_ALGOR *a;
if (ctx == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err;
}
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);
if (buf_in == NULL || buf_out == NULL) {
outl = 0;
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err;
}
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);
if (ctx == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
return 0;
}
/* 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);
if (buf_in == NULL || buf_out == NULL) {
outl = 0;
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err;
}
diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c
index b31761aae6..29ea60596e 100644
--- a/crypto/asn1/a_strex.c
+++ b/crypto/asn1/a_strex.c
@@ -282,10 +282,8 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg,
der_len = i2d_ASN1_TYPE(&t, NULL);
if (der_len <= 0)
return -1;
- if ((der_buf = OPENSSL_malloc(der_len)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((der_buf = OPENSSL_malloc(der_len)) == NULL)
return -1;
- }
p = der_buf;
i2d_ASN1_TYPE(&t, &p);
outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c
index 2c6cb919f7..869ac82714 100644
--- a/crypto/asn1/a_strnid.c
+++ b/crypto/asn1/a_strnid.c
@@ -159,10 +159,8 @@ static ASN1_STRING_TABLE *stable_get(int nid)
tmp = ASN1_STRING_TABLE_get(nid);
if (tmp != NULL && tmp->flags & STABLE_FLAGS_MALLOC)
return tmp;
- if ((rv = OPENSSL_zalloc(sizeof(*rv))) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((rv = OPENSSL_zalloc(sizeof(*rv))) == NULL)
return NULL;
- }
if (!sk_ASN1_STRING_TABLE_push(stable, rv)) {
OPENSSL_free(rv);
return NULL;
@@ -190,7 +188,7 @@ int ASN1_STRING_TABLE_add(int nid,
tmp = stable_get(nid);
if (tmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0;
}
if (minsize >= 0)
diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
index 92be1109a2..4459a68156 100644
--- a/crypto/asn1/a_time.c
+++ b/crypto/asn1/a_time.c
@@ -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.
*/
t.data = OPENSSL_zalloc(t.length + 1);
- if (t.data == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (t.data == NULL)
goto out;
- }
memcpy(t.data, str + 2, t.length);
t.type = V_ASN1_UTCTIME;
}
diff --git a/crypto/asn1/a_verify.c b/crypto/asn1/a_verify.c
index 9bf9bdd14e..a55f60d757 100644
--- a/crypto/asn1/a_verify.c
+++ b/crypto/asn1/a_verify.c
@@ -33,7 +33,7 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
int ret = -1, i, inl;
if (ctx == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
goto err;
}
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;
}
buf_in = OPENSSL_malloc((unsigned int)inl);
- if (buf_in == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (buf_in == NULL)
goto err;
- }
p = buf_in;
i2d(data, &p);
@@ -206,7 +204,7 @@ int ASN1_item_verify_ctx(const ASN1_ITEM *it, const X509_ALGOR *alg,
goto err;
}
if (buf_in == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
inll = inl;
diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c
index 8b15da3bee..6ba13dd7f2 100644
--- a/crypto/asn1/ameth_lib.c
+++ b/crypto/asn1/ameth_lib.c
@@ -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));
- if (ameth == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ameth == NULL)
return NULL;
- }
ameth->pkey_id = id;
ameth->pkey_base_id = id;
@@ -247,7 +245,6 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
err:
EVP_PKEY_asn1_free(ameth);
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
return NULL;
}
diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c
index c590c62fc2..a7ec79faa9 100644
--- a/crypto/asn1/asn1_gen.c
+++ b/crypto/asn1/asn1_gen.c
@@ -581,7 +581,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
int no_unused = 1;
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;
}
@@ -642,11 +642,11 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
goto bad_form;
}
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;
}
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;
}
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,
-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;
}
@@ -686,7 +686,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
case V_ASN1_BIT_STRING:
case V_ASN1_OCTET_STRING:
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;
}
@@ -750,7 +750,7 @@ static int bitstr_cb(const char *elem, int len, void *bitstr)
return 0;
}
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 1;
diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c
index 55e3ddbafd..e3a8480eef 100644
--- a/crypto/asn1/asn1_lib.c
+++ b/crypto/asn1/asn1_lib.c
@@ -314,7 +314,6 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len_in)
str->data = OPENSSL_realloc(c, len + 1);
#endif
if (str->data == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
str->data = c;
return 0;
}
@@ -354,10 +353,8 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
ASN1_STRING *ret;
ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
ret->type = type;
return ret;
}
diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c
index 1a60540885..014e482e66 100644
--- a/crypto/asn1/asn_mime.c
+++ b/crypto/asn1/asn_mime.c
@@ -76,7 +76,7 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
BIO *bio, *tbio;
bio = BIO_new_NDEF(out, val, it);
if (!bio) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_BUF_LIB);
return 0;
}
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;
b64 = BIO_new(BIO_f_base64());
if (b64 == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_BIO_LIB);
return 0;
}
/*
@@ -142,7 +142,7 @@ static ASN1_VALUE *b64_read_asn1(BIO *bio, const ASN1_ITEM *it, ASN1_VALUE **x,
ASN1_VALUE *val;
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;
}
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());
if (bf == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_BIO_LIB);
return 0;
}
out = BIO_push(bf, out);
diff --git a/crypto/asn1/asn_moid.c b/crypto/asn1/asn_moid.c
index 526219c1a7..6f816307af 100644
--- a/crypto/asn1/asn_moid.c
+++ b/crypto/asn1/asn_moid.c
@@ -83,10 +83,8 @@ static int do_create(const char *value, const char *name)
p--;
}
p++;
- if ((lntmp = OPENSSL_malloc((p - ln) + 1)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((lntmp = OPENSSL_malloc((p - ln) + 1)) == NULL)
return 0;
- }
memcpy(lntmp, ln, p - ln);
lntmp[p - ln] = '\0';
ln = lntmp;
diff --git a/crypto/asn1/asn_mstbl.c b/crypto/asn1/asn_mstbl.c
index 3543cd2256..515d8181b6 100644
--- a/crypto/asn1/asn_mstbl.c
+++ b/crypto/asn1/asn_mstbl.c
@@ -106,7 +106,7 @@ static int do_tcreate(const char *value, const char *name)
rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max,
tbl_mask, tbl_flags);
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);
return rv;
diff --git a/crypto/asn1/asn_pack.c b/crypto/asn1/asn_pack.c
index bf6e273b93..0744e7b434 100644
--- a/crypto/asn1/asn_pack.c
+++ b/crypto/asn1/asn_pack.c
@@ -19,7 +19,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
if (oct == NULL || *oct == 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;
}
} else {
@@ -33,7 +33,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
goto err;
}
if (octmp->data == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c
index f792c08806..c6eabc0d61 100644
--- a/crypto/asn1/bio_asn1.c
+++ b/crypto/asn1/bio_asn1.c
@@ -100,10 +100,8 @@ static int asn1_bio_new(BIO *b)
{
BIO_ASN1_BUF_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
- if (ctx == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ctx == NULL)
return 0;
- }
if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) {
OPENSSL_free(ctx);
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)
{
- if (size <= 0 || (ctx->buf = OPENSSL_malloc(size)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (size <= 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_INVALID_ARGUMENT);
return 0;
}
+ if ((ctx->buf = OPENSSL_malloc(size)) == NULL)
+ return 0;
ctx->bufsize = size;
ctx->asn1_class = V_ASN1_UNIVERSAL;
ctx->asn1_tag = V_ASN1_OCTET_STRING;
diff --git a/crypto/asn1/bio_ndef.c b/crypto/asn1/bio_ndef.c
index d94e3a3644..108f7c8285 100644
--- a/crypto/asn1/bio_ndef.c
+++ b/crypto/asn1/bio_ndef.c
@@ -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);
if (derlen < 0)
return 0;
- if ((p = OPENSSL_malloc(derlen)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((p = OPENSSL_malloc(derlen)) == NULL)
return 0;
- }
ndef_aux->derbuf = 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);
if (derlen < 0)
return 0;
- if ((p = OPENSSL_malloc(derlen)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((p = OPENSSL_malloc(derlen)) == NULL)
return 0;
- }
ndef_aux->derbuf = p;
*pbuf = p;
diff --git a/crypto/asn1/f_int.c b/crypto/asn1/f_int.c
index d41e0069af..20192b577b 100644
--- a/crypto/asn1/f_int.c
+++ b/crypto/asn1/f_int.c
@@ -108,7 +108,6 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
if (num + i > slen) {
sp = OPENSSL_clear_realloc(s, slen, num + i * 2);
if (sp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
OPENSSL_free(s);
return 0;
}
diff --git a/crypto/asn1/f_string.c b/crypto/asn1/f_string.c
index 4b65110d98..1da442a457 100644
--- a/crypto/asn1/f_string.c
+++ b/crypto/asn1/f_string.c
@@ -99,7 +99,6 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
if (num + i > slen) {
sp = OPENSSL_realloc(s, (unsigned int)num + i * 2);
if (sp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
OPENSSL_free(s);
return 0;
}
diff --git a/crypto/asn1/p5_pbe.c b/crypto/asn1/p5_pbe.c
index 9bc8aaa7a3..13b3f19bae 100644
--- a/crypto/asn1/p5_pbe.c
+++ b/crypto/asn1/p5_pbe.c
@@ -34,13 +34,14 @@ int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter,
pbe = PBEPARAM_new();
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;
}
if (iter <= 0)
iter = PKCS5_DEFAULT_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;
}
if (!saltlen)
@@ -49,10 +50,8 @@ int PKCS5_pbe_set0_algor_ex(X509_ALGOR *algor, int alg, int iter,
goto err;
sstr = OPENSSL_malloc(saltlen);
- if (sstr == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (sstr == NULL)
goto err;
- }
if (salt)
memcpy(sstr, salt, saltlen);
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;
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;
}
@@ -94,7 +93,7 @@ X509_ALGOR *PKCS5_pbe_set_ex(int alg, int iter,
X509_ALGOR *ret;
ret = X509_ALGOR_new();
if (ret == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
return NULL;
}
diff --git a/crypto/asn1/p5_pbev2.c b/crypto/asn1/p5_pbev2.c
index b44e447cef..e710cf3c35 100644
--- a/crypto/asn1/p5_pbev2.c
+++ b/crypto/asn1/p5_pbev2.c
@@ -57,14 +57,18 @@ X509_ALGOR *PKCS5_pbe2_set_iv_ex(const EVP_CIPHER *cipher, int iter,
goto err;
}
- if ((pbe2 = PBE2PARAM_new()) == NULL)
- goto merr;
+ if ((pbe2 = PBE2PARAM_new()) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* Setup the AlgorithmIdentifier for the encryption scheme */
scheme = pbe2->encryption;
scheme->algorithm = OBJ_nid2obj(alg_nid);
- if ((scheme->parameter = ASN1_TYPE_new()) == NULL)
- goto merr;
+ if ((scheme->parameter = ASN1_TYPE_new()) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* Create random IV */
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();
- if (ctx == NULL)
- goto merr;
+ if (ctx == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
+ goto err;
+ }
/* Dummy cipherinit to just setup the IV, and PRF */
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,
libctx);
- if (pbe2->keyfunc == NULL)
- goto merr;
+ if (pbe2->keyfunc == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* Now set up top level AlgorithmIdentifier */
- if ((ret = X509_ALGOR_new()) == NULL)
- goto merr;
+ if ((ret = X509_ALGOR_new()) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
+ goto err;
+ }
ret->algorithm = OBJ_nid2obj(NID_pbes2);
/* Encode PBE2PARAM into parameter */
if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2,
- &ret->parameter))
- goto merr;
+ &ret->parameter)) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
PBE2PARAM_free(pbe2);
pbe2 = NULL;
return ret;
- merr:
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
-
err:
EVP_CIPHER_CTX_free(ctx);
PBE2PARAM_free(pbe2);
@@ -170,69 +179,89 @@ X509_ALGOR *PKCS5_pbkdf2_set_ex(int iter, unsigned char *salt, int saltlen,
PBKDF2PARAM *kdf = NULL;
ASN1_OCTET_STRING *osalt = NULL;
- if ((kdf = PBKDF2PARAM_new()) == NULL)
- goto merr;
- if ((osalt = ASN1_OCTET_STRING_new()) == NULL)
- goto merr;
+ if ((kdf = PBKDF2PARAM_new()) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
+ 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->type = V_ASN1_OCTET_STRING;
- if (saltlen < 0)
- goto merr;
+ if (saltlen < 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_INVALID_ARGUMENT);
+ goto err;
+ }
if (saltlen == 0)
saltlen = PKCS5_SALT_LEN;
if ((osalt->data = OPENSSL_malloc(saltlen)) == NULL)
- goto merr;
+ goto err;
+
osalt->length = saltlen;
- if (salt)
+ if (salt) {
memcpy(osalt->data, salt, saltlen);
- else if (RAND_bytes_ex(libctx, osalt->data, saltlen, 0) <= 0)
- goto merr;
+ } else if (RAND_bytes_ex(libctx, osalt->data, saltlen, 0) <= 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_RAND_LIB);
+ goto err;
+ }
if (iter <= 0)
iter = PKCS5_DEFAULT_ITER;
- if (!ASN1_INTEGER_set(kdf->iter, iter))
- goto merr;
+ if (!ASN1_INTEGER_set(kdf->iter, iter)) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* If have a key len set it up */
if (keylen > 0) {
- if ((kdf->keylength = ASN1_INTEGER_new()) == NULL)
- goto merr;
- if (!ASN1_INTEGER_set(kdf->keylength, keylen))
- goto merr;
+ if ((kdf->keylength = ASN1_INTEGER_new()) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
+ 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 */
if (prf_nid > 0 && prf_nid != NID_hmacWithSHA1) {
kdf->prf = ossl_X509_ALGOR_from_nid(prf_nid, V_ASN1_NULL, NULL);
- if (kdf->prf == NULL)
- goto merr;
+ if (kdf->prf == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
+ goto err;
+ }
}
/* Finally setup the keyfunc structure */
keyfunc = X509_ALGOR_new();
- if (keyfunc == NULL)
- goto merr;
+ if (keyfunc == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_X509_LIB);
+ goto err;
+ }
keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
/* Encode PBKDF2PARAM into parameter of pbe2 */
if (!ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBKDF2PARAM), kdf,
- &keyfunc->parameter))
- goto merr;
+ &keyfunc->parameter)) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
PBKDF2PARAM_free(kdf);
return keyfunc;
- merr:
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ err:
PBKDF2PARAM_free(kdf);
X509_ALGOR_free(keyfunc);
return NULL;
diff --git a/crypto/asn1/p5_scrypt.c b/crypto/asn1/p5_scrypt.c
index a02190d0dc..94b77fd3ab 100644
--- a/crypto/asn1/p5_scrypt.c
+++ b/crypto/asn1/p5_scrypt.c
@@ -67,16 +67,20 @@ X509_ALGOR *PKCS5_pbe2_set_scrypt(const EVP_CIPHER *cipher,
}
pbe2 = PBE2PARAM_new();
- if (pbe2 == NULL)
- goto merr;
+ if (pbe2 == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* Setup the AlgorithmIdentifier for the encryption scheme */
scheme = pbe2->encryption;
scheme->algorithm = OBJ_nid2obj(alg_nid);
scheme->parameter = ASN1_TYPE_new();
- if (scheme->parameter == NULL)
- goto merr;
+ if (scheme->parameter == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* Create random IV */
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();
- if (ctx == NULL)
- goto merr;
+ if (ctx == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_EVP_LIB);
+ goto err;
+ }
/* Dummy cipherinit to just setup the IV */
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);
- if (pbe2->keyfunc == NULL)
- goto merr;
+ if (pbe2->keyfunc == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* Now set up top level AlgorithmIdentifier */
ret = X509_ALGOR_new();
- if (ret == NULL)
- goto merr;
+ if (ret == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
ret->algorithm = OBJ_nid2obj(NID_pbes2);
/* Encode PBE2PARAM into parameter */
if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(PBE2PARAM), pbe2,
- &ret->parameter) == NULL)
- goto merr;
+ &ret->parameter) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
PBE2PARAM_free(pbe2);
pbe2 = NULL;
return ret;
- merr:
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
-
err:
PBE2PARAM_free(pbe2);
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;
SCRYPT_PARAMS *sparam = SCRYPT_PARAMS_new();
- if (sparam == NULL)
- goto merr;
+ if (sparam == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
if (!saltlen)
saltlen = PKCS5_SALT_LEN;
/* This will either copy salt or grow the buffer */
- if (ASN1_STRING_set(sparam->salt, salt, saltlen) == 0)
- goto merr;
+ if (ASN1_STRING_set(sparam->salt, salt, saltlen) == 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
if (salt == NULL && RAND_bytes(sparam->salt->data, saltlen) <= 0)
goto err;
- if (ASN1_INTEGER_set_uint64(sparam->costParameter, N) == 0)
- goto merr;
+ if (ASN1_INTEGER_set_uint64(sparam->costParameter, N) == 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
- if (ASN1_INTEGER_set_uint64(sparam->blockSize, r) == 0)
- goto merr;
+ if (ASN1_INTEGER_set_uint64(sparam->blockSize, r) == 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
- if (ASN1_INTEGER_set_uint64(sparam->parallelizationParameter, p) == 0)
- goto merr;
+ if (ASN1_INTEGER_set_uint64(sparam->parallelizationParameter, p) == 0) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
/* If have a key len set it up */
if (keylen > 0) {
sparam->keyLength = ASN1_INTEGER_new();
- if (sparam->keyLength == NULL)
- goto merr;
- if (ASN1_INTEGER_set_int64(sparam->keyLength, keylen) == 0)
- goto merr;
+ if (sparam->keyLength == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
+ 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 */
keyfunc = X509_ALGOR_new();
- if (keyfunc == NULL)
- goto merr;
+ if (keyfunc == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
keyfunc->algorithm = OBJ_nid2obj(NID_id_scrypt);
/* Encode SCRYPT_PARAMS into parameter of pbe2 */
if (ASN1_TYPE_pack_sequence(ASN1_ITEM_rptr(SCRYPT_PARAMS), sparam,
- &keyfunc->parameter) == NULL)
- goto merr;
+ &keyfunc->parameter) == NULL) {
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ goto err;
+ }
SCRYPT_PARAMS_free(sparam);
return keyfunc;
- merr:
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
err:
SCRYPT_PARAMS_free(sparam);
X509_ALGOR_free(keyfunc);
diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c
index 1701eb9d56..5c65d542c5 100644
--- a/crypto/asn1/tasn_dec.c
+++ b/crypto/asn1/tasn_dec.c
@@ -629,7 +629,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
}
if (*val == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
goto err;
}
@@ -658,7 +658,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
}
len -= p - q;
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));
goto err;
}
@@ -802,7 +802,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
len = buf.length;
/* Append a final null to string */
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;
}
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) {
stmp = ASN1_STRING_type_new(utype);
if (stmp == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
goto err;
}
*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;
} else {
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);
*pval = NULL;
goto err;
@@ -1098,7 +1098,7 @@ static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
if (buf) {
len = buf->length;
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;
}
memcpy(buf->data + len, *p, plen);
diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c
index 3ea18b0280..dab5f9f278 100644
--- a/crypto/asn1/tasn_enc.c
+++ b/crypto/asn1/tasn_enc.c
@@ -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);
if (len <= 0)
return len;
- if ((buf = OPENSSL_malloc(len)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((buf = OPENSSL_malloc(len)) == NULL)
return -1;
- }
p = buf;
ASN1_item_ex_i2d(&val, &p, it, -1, flags);
*out = buf;
@@ -415,15 +413,11 @@ static int asn1_set_seq_out(STACK_OF(const_ASN1_VALUE) *sk,
else {
derlst = OPENSSL_malloc(sk_const_ASN1_VALUE_num(sk)
* sizeof(*derlst));
- if (derlst == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (derlst == NULL)
return 0;
- }
tmpdat = OPENSSL_malloc(skcontlen);
- if (tmpdat == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (tmpdat == NULL)
goto err;
- }
}
}
/* If not sorting just output each item */
diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c
index 4b624bbdd4..00a5397a5e 100644
--- a/crypto/asn1/tasn_new.c
+++ b/crypto/asn1/tasn_new.c
@@ -78,10 +78,10 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
if (ef != NULL) {
if (ef->asn1_ex_new_ex != NULL) {
if (!ef->asn1_ex_new_ex(pval, it, libctx, propq))
- goto memerr;
+ goto asn1err;
} else if (ef->asn1_ex_new != NULL) {
if (!ef->asn1_ex_new(pval, it))
- goto memerr;
+ goto asn1err;
}
}
break;
@@ -89,14 +89,14 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
case ASN1_ITYPE_PRIMITIVE:
if (it->templates) {
if (!asn1_template_new(pval, it->templates, libctx, propq))
- goto memerr;
+ goto asn1err;
} else if (!asn1_primitive_new(pval, it, embed))
- goto memerr;
+ goto asn1err;
break;
case ASN1_ITYPE_MSTRING:
if (!asn1_primitive_new(pval, it, embed))
- goto memerr;
+ goto asn1err;
break;
case ASN1_ITYPE_CHOICE:
@@ -113,7 +113,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
} else {
*pval = OPENSSL_zalloc(it->size);
if (*pval == NULL)
- goto memerr;
+ return 0;
}
ossl_asn1_set_choice_selector(pval, -1, it);
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 {
*pval = OPENSSL_zalloc(it->size);
if (*pval == NULL)
- goto memerr;
+ return 0;
}
/* 0 : init. lock */
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);
*pval = NULL;
}
- goto memerr;
+ goto asn1err;
}
ossl_asn1_enc_init(pval, it);
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
pseqval = ossl_asn1_get_field_ptr(pval, tt);
if (!asn1_template_new(pseqval, tt, libctx, propq))
- goto memerr2;
+ goto asn1err2;
}
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
goto auxerr2;
@@ -157,10 +157,10 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed,
}
return 1;
- memerr2:
+ asn1err2:
ossl_asn1_item_embed_free(pval, it, embed);
- memerr:
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ asn1err:
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
return 0;
auxerr2:
@@ -230,7 +230,7 @@ static int asn1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
STACK_OF(ASN1_VALUE) *skval;
skval = sk_ASN1_VALUE_new_null();
if (!skval) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
ret = 0;
goto done;
}
@@ -298,10 +298,8 @@ static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
return 1;
case V_ASN1_ANY:
- if ((typ = OPENSSL_malloc(sizeof(*typ))) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((typ = OPENSSL_malloc(sizeof(*typ))) == NULL)
return 0;
- }
typ->value.ptr = NULL;
typ->type = -1;
*pval = (ASN1_VALUE *)typ;
diff --git a/crypto/asn1/tasn_prn.c b/crypto/asn1/tasn_prn.c
index 7d8618e26c..73eadc5fd4 100644
--- a/crypto/asn1/tasn_prn.c
+++ b/crypto/asn1/tasn_prn.c
@@ -37,10 +37,8 @@ ASN1_PCTX *ASN1_PCTX_new(void)
ASN1_PCTX *ret;
ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
return ret;
}
diff --git a/crypto/asn1/tasn_scn.c b/crypto/asn1/tasn_scn.c
index bde697ee99..7ada313b94 100644
--- a/crypto/asn1/tasn_scn.c
+++ b/crypto/asn1/tasn_scn.c
@@ -26,10 +26,8 @@ ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx))
{
ASN1_SCTX *ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
ret->scan_cb = scan_cb;
return ret;
}
diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c
index e5f25d88df..be8931cab4 100644
--- a/crypto/asn1/tasn_utl.c
+++ b/crypto/asn1/tasn_utl.c
@@ -86,7 +86,7 @@ int ossl_asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
*lck = ret = 1;
*lock = CRYPTO_THREAD_lock_new();
if (*lock == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_CRYPTO_LIB);
return -1;
}
break;
@@ -168,10 +168,8 @@ int ossl_asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
OPENSSL_free(enc->enc);
if (inlen <= 0)
return 0;
- if ((enc->enc = OPENSSL_malloc(inlen)) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((enc->enc = OPENSSL_malloc(inlen)) == NULL)
return 0;
- }
memcpy(enc->enc, in, inlen);
enc->len = inlen;
enc->modified = 0;
diff --git a/crypto/asn1/x_info.c b/crypto/asn1/x_info.c
index f8bc478988..8a4d2dba0a 100644
--- a/crypto/asn1/x_info.c
+++ b/crypto/asn1/x_info.c
@@ -18,10 +18,8 @@ X509_INFO *X509_INFO_new(void)
X509_INFO *ret;
ret = OPENSSL_zalloc(sizeof(*ret));
- if (ret == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if (ret == NULL)
return NULL;
- }
return ret;
}
diff --git a/crypto/asn1/x_int64.c b/crypto/asn1/x_int64.c
index eb78c7e367..d05fe26bb0 100644
--- a/crypto/asn1/x_int64.c
+++ b/crypto/asn1/x_int64.c
@@ -28,10 +28,8 @@
static int uint64_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
- if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint64_t))) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint64_t))) == NULL)
return 0;
- }
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)
{
- if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint32_t))) == NULL) {
- ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
+ if ((*pval = (ASN1_VALUE *)OPENSSL_zalloc(sizeof(uint32_t))) == NULL)
return 0;
- }
return 1;
}
diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c
index b63c7c6489..34b7286d7e 100644
--- a/crypto/asn1/x_pkey.c
+++ b/crypto/asn1/x_pkey.c
@@ -19,18 +19,17 @@ X509_PKEY *X509_PKEY_new(void)
ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL)
- goto err;
+ return NULL;
ret->enc_algor = X509_ALGOR_new();
ret->enc_pkey = ASN1_OCTET_STRING_new();
- if (ret->enc_algor == NULL || ret->enc_pkey == NULL)
- goto err;
+ if (ret->enc_algor == NULL || ret->enc_pkey == NULL) {
+ X509_PKEY_free(ret);
+ ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
+ return NULL;
+ }
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)