diff options
author | Rich Salz <rsalz@akamai.com> | 2015-05-02 05:10:31 +0200 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-05-04 21:00:13 +0200 |
commit | b4faea50c35d92a67d1369355b49cc3efba78406 (patch) | |
tree | cfebea69d625f936c9fd7281f1fa3eaa2fa38834 /crypto/objects/o_names.c | |
parent | RT2943: Check sizes if -iv and -K arguments (diff) | |
download | openssl-b4faea50c35d92a67d1369355b49cc3efba78406.tar.xz openssl-b4faea50c35d92a67d1369355b49cc3efba78406.zip |
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/objects/o_names.c')
-rw-r--r-- | crypto/objects/o_names.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/crypto/objects/o_names.c b/crypto/objects/o_names.c index 1fa6426a4f..d861b6d083 100644 --- a/crypto/objects/o_names.c +++ b/crypto/objects/o_names.c @@ -83,7 +83,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), names_type_num++; for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) { MemCheck_off(); - name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS)); + name_funcs = OPENSSL_malloc(sizeof(*name_funcs)); MemCheck_on(); if (!name_funcs) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); @@ -187,7 +187,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data) alias = type & OBJ_NAME_ALIAS; type &= ~OBJ_NAME_ALIAS; - onp = OPENSSL_malloc(sizeof(OBJ_NAME)); + onp = OPENSSL_malloc(sizeof(*onp)); if (onp == NULL) { /* ERROR */ return (0); @@ -310,13 +310,13 @@ void OBJ_NAME_do_all_sorted(int type, d.type = type; d.names = - OPENSSL_malloc(lh_OBJ_NAME_num_items(names_lh) * sizeof *d.names); + OPENSSL_malloc(sizeof(*d.names) * lh_OBJ_NAME_num_items(names_lh)); /* Really should return an error if !d.names...but its a void function! */ if (d.names) { d.n = 0; OBJ_NAME_do_all(type, do_all_sorted_fn, &d); - qsort((void *)d.names, d.n, sizeof *d.names, do_all_sorted_cmp); + qsort((void *)d.names, d.n, sizeof(*d.names), do_all_sorted_cmp); for (n = 0; n < d.n; ++n) fn(d.names[n], arg); |