diff options
author | Rich Salz <rsalz@akamai.com> | 2015-05-01 23:10:31 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-05-04 15:00:13 -0400 |
commit | b4faea50c35d92a67d1369355b49cc3efba78406 (patch) | |
tree | cfebea69d625f936c9fd7281f1fa3eaa2fa38834 /crypto/x509v3 | |
parent | 8920a7cd04f43b1a090d0b0a8c9e16b94c6898d4 (diff) | |
download | openssl-new-b4faea50c35d92a67d1369355b49cc3efba78406.tar.gz |
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/x509v3')
-rw-r--r-- | crypto/x509v3/pcy_cache.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/pcy_data.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/pcy_node.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/pcy_tree.c | 4 | ||||
-rw-r--r-- | crypto/x509v3/v3_asid.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/v3_lib.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/v3_purp.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/v3_scts.c | 2 | ||||
-rw-r--r-- | crypto/x509v3/v3_utl.c | 2 |
9 files changed, 10 insertions, 10 deletions
diff --git a/crypto/x509v3/pcy_cache.c b/crypto/x509v3/pcy_cache.c index 1f942604d8..8e78011858 100644 --- a/crypto/x509v3/pcy_cache.c +++ b/crypto/x509v3/pcy_cache.c @@ -127,7 +127,7 @@ static int policy_cache_new(X509 *x) CERTIFICATEPOLICIES *ext_cpols = NULL; POLICY_MAPPINGS *ext_pmaps = NULL; int i; - cache = OPENSSL_malloc(sizeof(X509_POLICY_CACHE)); + cache = OPENSSL_malloc(sizeof(*cache)); if (!cache) return 0; cache->anyPolicy = NULL; diff --git a/crypto/x509v3/pcy_data.c b/crypto/x509v3/pcy_data.c index 37c867ef91..ef6edb1fe5 100644 --- a/crypto/x509v3/pcy_data.c +++ b/crypto/x509v3/pcy_data.c @@ -98,7 +98,7 @@ X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, return NULL; } else id = NULL; - ret = OPENSSL_malloc(sizeof(X509_POLICY_DATA)); + ret = OPENSSL_malloc(sizeof(*ret)); if (!ret) return NULL; ret->expected_policy_set = sk_ASN1_OBJECT_new_null(); diff --git a/crypto/x509v3/pcy_node.c b/crypto/x509v3/pcy_node.c index d6c917650a..855fe3ed94 100644 --- a/crypto/x509v3/pcy_node.c +++ b/crypto/x509v3/pcy_node.c @@ -114,7 +114,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, X509_POLICY_TREE *tree) { X509_POLICY_NODE *node; - node = OPENSSL_malloc(sizeof(X509_POLICY_NODE)); + node = OPENSSL_malloc(sizeof(*node)); if (!node) return NULL; node->data = data; diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c index f1bcb053a9..8870ec2238 100644 --- a/crypto/x509v3/pcy_tree.c +++ b/crypto/x509v3/pcy_tree.c @@ -218,13 +218,13 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs, /* If we get this far initialize the tree */ - tree = OPENSSL_malloc(sizeof(X509_POLICY_TREE)); + tree = OPENSSL_malloc(sizeof(*tree)); if (!tree) return 0; tree->flags = 0; - tree->levels = OPENSSL_malloc(sizeof(X509_POLICY_LEVEL) * n); + tree->levels = OPENSSL_malloc(sizeof(*tree->levels) * n); tree->nlevel = 0; tree->extra_data = NULL; tree->auth_policies = NULL; diff --git a/crypto/x509v3/v3_asid.c b/crypto/x509v3/v3_asid.c index 34469eb7ba..d7f58486fb 100644 --- a/crypto/x509v3/v3_asid.c +++ b/crypto/x509v3/v3_asid.c @@ -471,7 +471,7 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) ASRange *r; switch (a->type) { case ASIdOrRange_id: - if ((r = OPENSSL_malloc(sizeof(ASRange))) == NULL) { + if ((r = OPENSSL_malloc(sizeof(*r))) == NULL) { X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, ERR_R_MALLOC_FAILURE); goto done; diff --git a/crypto/x509v3/v3_lib.c b/crypto/x509v3/v3_lib.c index 3396ff1c76..c091b043de 100644 --- a/crypto/x509v3/v3_lib.c +++ b/crypto/x509v3/v3_lib.c @@ -140,7 +140,7 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from) X509V3_R_EXTENSION_NOT_FOUND); return 0; } - if (!(tmpext = OPENSSL_malloc(sizeof(X509V3_EXT_METHOD)))) { + if (!(tmpext = OPENSSL_malloc(sizeof(*tmpext)))) { X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index 5cee586990..ed634cb2f5 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -209,7 +209,7 @@ int X509_PURPOSE_add(int id, int trust, int flags, idx = X509_PURPOSE_get_by_id(id); /* Need a new entry */ if (idx == -1) { - if (!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) { + if (!(ptmp = OPENSSL_malloc(sizeof(*ptmp)))) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/x509v3/v3_scts.c b/crypto/x509v3/v3_scts.c index 2bbc05655b..31e610d434 100644 --- a/crypto/x509v3/v3_scts.c +++ b/crypto/x509v3/v3_scts.c @@ -203,7 +203,7 @@ static STACK_OF(SCT) *d2i_SCT_LIST(STACK_OF(SCT) **a, goto err; listlen -= sctlen; - sct = OPENSSL_malloc(sizeof(SCT)); + sct = OPENSSL_malloc(sizeof(*sct)); if (!sct) goto err; if (!sk_SCT_push(sk, sct)) { diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index 71422083e7..a5fda6fd10 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -88,7 +88,7 @@ int X509V3_add_value(const char *name, const char *value, goto err; if (value && !(tvalue = BUF_strdup(value))) goto err; - if (!(vtmp = OPENSSL_malloc(sizeof(CONF_VALUE)))) + if (!(vtmp = OPENSSL_malloc(sizeof(*vtmp)))) goto err; if (!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err; |