summaryrefslogtreecommitdiffstats
path: root/crypto/asn1
diff options
context:
space:
mode:
authorRich Salz <rsalz@akamai.com>2015-05-01 23:10:31 -0400
committerRich Salz <rsalz@openssl.org>2015-05-04 15:00:13 -0400
commitb4faea50c35d92a67d1369355b49cc3efba78406 (patch)
treecfebea69d625f936c9fd7281f1fa3eaa2fa38834 /crypto/asn1
parent8920a7cd04f43b1a090d0b0a8c9e16b94c6898d4 (diff)
Use safer sizeof variant in malloc
For a local variable: TYPE *p; Allocations like this are "risky": p = OPENSSL_malloc(sizeof(TYPE)); if the type of p changes, and the malloc call isn't updated, you could get memory corruption. Instead do this: p = OPENSSL_malloc(sizeof(*p)); Also fixed a few memset() calls that I noticed while doing this. Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/asn1')
-rw-r--r--crypto/asn1/a_object.c2
-rw-r--r--crypto/asn1/a_strnid.c2
-rw-r--r--crypto/asn1/ameth_lib.c2
-rw-r--r--crypto/asn1/asn1_lib.c2
-rw-r--r--crypto/asn1/asn_mime.c4
-rw-r--r--crypto/asn1/bio_asn1.c2
-rw-r--r--crypto/asn1/bio_ndef.c2
-rw-r--r--crypto/asn1/tasn_new.c2
-rw-r--r--crypto/asn1/tasn_prn.c2
-rw-r--r--crypto/asn1/tasn_scn.c2
-rw-r--r--crypto/asn1/x_crl.c2
-rw-r--r--crypto/asn1/x_info.c2
-rw-r--r--crypto/asn1/x_pkey.c4
13 files changed, 15 insertions, 15 deletions
diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c
index 809e9a4112..7cedce82e7 100644
--- a/crypto/asn1/a_object.c
+++ b/crypto/asn1/a_object.c
@@ -345,7 +345,7 @@ ASN1_OBJECT *ASN1_OBJECT_new(void)
{
ASN1_OBJECT *ret;
- ret = OPENSSL_malloc(sizeof(ASN1_OBJECT));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret == NULL) {
ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c
index 5126298673..071613b89b 100644
--- a/crypto/asn1/a_strnid.c
+++ b/crypto/asn1/a_strnid.c
@@ -240,7 +240,7 @@ static ASN1_STRING_TABLE *stable_get(int nid)
tmp = ASN1_STRING_TABLE_get(nid);
if (tmp && tmp->flags & STABLE_FLAGS_MALLOC)
return tmp;
- rv = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
+ rv = OPENSSL_malloc(sizeof(*rv));
if (!rv)
return NULL;
if (!sk_ASN1_STRING_TABLE_push(stable, rv)) {
diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c
index 49f4e5abbf..c7acb468a6 100644
--- a/crypto/asn1/ameth_lib.c
+++ b/crypto/asn1/ameth_lib.c
@@ -284,7 +284,7 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
const char *pem_str, const char *info)
{
EVP_PKEY_ASN1_METHOD *ameth;
- ameth = OPENSSL_malloc(sizeof(EVP_PKEY_ASN1_METHOD));
+ ameth = OPENSSL_malloc(sizeof(*ameth));
if (!ameth)
return NULL;
diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c
index e1e509b3ec..bda6ab09b4 100644
--- a/crypto/asn1/asn1_lib.c
+++ b/crypto/asn1/asn1_lib.c
@@ -349,7 +349,7 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
{
ASN1_STRING *ret;
- ret = OPENSSL_malloc(sizeof(ASN1_STRING));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret == NULL) {
ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c
index e8411a82ad..da5b417048 100644
--- a/crypto/asn1/asn_mime.c
+++ b/crypto/asn1/asn_mime.c
@@ -844,7 +844,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
}
}
}
- mhdr = OPENSSL_malloc(sizeof(MIME_HEADER));
+ mhdr = OPENSSL_malloc(sizeof(*mhdr));
if (!mhdr)
goto err;
mhdr->name = tmpname;
@@ -883,7 +883,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
goto err;
}
/* Parameter values are case sensitive so leave as is */
- mparam = OPENSSL_malloc(sizeof(MIME_PARAM));
+ mparam = OPENSSL_malloc(sizeof(*mparam));
if (!mparam)
goto err;
mparam->param_name = tmpname;
diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c
index ba39069374..910d06f04d 100644
--- a/crypto/asn1/bio_asn1.c
+++ b/crypto/asn1/bio_asn1.c
@@ -146,7 +146,7 @@ BIO_METHOD *BIO_f_asn1(void)
static int asn1_bio_new(BIO *b)
{
BIO_ASN1_BUF_CTX *ctx;
- ctx = OPENSSL_malloc(sizeof(BIO_ASN1_BUF_CTX));
+ ctx = OPENSSL_malloc(sizeof(*ctx));
if (!ctx)
return 0;
if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) {
diff --git a/crypto/asn1/bio_ndef.c b/crypto/asn1/bio_ndef.c
index de517f22e4..ff2fdf529b 100644
--- a/crypto/asn1/bio_ndef.c
+++ b/crypto/asn1/bio_ndef.c
@@ -106,7 +106,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED);
return NULL;
}
- ndef_aux = OPENSSL_malloc(sizeof(NDEF_SUPPORT));
+ ndef_aux = OPENSSL_malloc(sizeof(*ndef_aux));
asn_bio = BIO_new(BIO_f_asn1());
/* ASN1 bio needs to be next to output BIO */
diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c
index aeced95232..f54bd9bcf1 100644
--- a/crypto/asn1/tasn_new.c
+++ b/crypto/asn1/tasn_new.c
@@ -319,7 +319,7 @@ static int asn1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
return 1;
case V_ASN1_ANY:
- typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
+ typ = OPENSSL_malloc(sizeof(*typ));
if (!typ)
return 0;
typ->value.ptr = NULL;
diff --git a/crypto/asn1/tasn_prn.c b/crypto/asn1/tasn_prn.c
index 76d584b2ba..e080e724a4 100644
--- a/crypto/asn1/tasn_prn.c
+++ b/crypto/asn1/tasn_prn.c
@@ -85,7 +85,7 @@ ASN1_PCTX default_pctx = {
ASN1_PCTX *ASN1_PCTX_new(void)
{
ASN1_PCTX *ret;
- ret = OPENSSL_malloc(sizeof(ASN1_PCTX));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret == NULL) {
ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/crypto/asn1/tasn_scn.c b/crypto/asn1/tasn_scn.c
index cedea9cb78..43a125cb55 100644
--- a/crypto/asn1/tasn_scn.c
+++ b/crypto/asn1/tasn_scn.c
@@ -75,7 +75,7 @@
ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx))
{
ASN1_SCTX *ret;
- ret = OPENSSL_malloc(sizeof(ASN1_SCTX));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret == NULL) {
ASN1err(ASN1_F_ASN1_SCTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
diff --git a/crypto/asn1/x_crl.c b/crypto/asn1/x_crl.c
index a32158b983..0d759beb6d 100644
--- a/crypto/asn1/x_crl.c
+++ b/crypto/asn1/x_crl.c
@@ -476,7 +476,7 @@ X509_CRL_METHOD *X509_CRL_METHOD_new(int (*crl_init) (X509_CRL *crl),
EVP_PKEY *pk))
{
X509_CRL_METHOD *m;
- m = OPENSSL_malloc(sizeof(X509_CRL_METHOD));
+ m = OPENSSL_malloc(sizeof(*m));
if (!m)
return NULL;
m->crl_init = crl_init;
diff --git a/crypto/asn1/x_info.c b/crypto/asn1/x_info.c
index 5b927efc67..856bcf58b2 100644
--- a/crypto/asn1/x_info.c
+++ b/crypto/asn1/x_info.c
@@ -66,7 +66,7 @@ X509_INFO *X509_INFO_new(void)
{
X509_INFO *ret = NULL;
- ret = OPENSSL_malloc(sizeof(X509_INFO));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret == NULL) {
ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
diff --git a/crypto/asn1/x_pkey.c b/crypto/asn1/x_pkey.c
index 59e002bd45..b01616fb8d 100644
--- a/crypto/asn1/x_pkey.c
+++ b/crypto/asn1/x_pkey.c
@@ -66,10 +66,10 @@ X509_PKEY *X509_PKEY_new(void)
{
X509_PKEY *ret = NULL;
- ret = OPENSSL_malloc(sizeof(X509_PKEY));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (!ret)
goto err;
- memset(ret, 0, sizeof(X509_PKEY));
+ memset(ret, 0, sizeof(*ret));
ret->version = 0;
ret->enc_algor = X509_ALGOR_new();