aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/conf
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/conf
parent8920a7cd04f43b1a090d0b0a8c9e16b94c6898d4 (diff)
downloadopenssl-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/conf')
-rw-r--r--crypto/conf/conf_api.c2
-rw-r--r--crypto/conf/conf_def.c4
-rw-r--r--crypto/conf/conf_mod.c4
3 files changed, 5 insertions, 5 deletions
diff --git a/crypto/conf/conf_api.c b/crypto/conf/conf_api.c
index 59808a301b..3badf7fc44 100644
--- a/crypto/conf/conf_api.c
+++ b/crypto/conf/conf_api.c
@@ -255,7 +255,7 @@ CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
if ((sk = sk_CONF_VALUE_new_null()) == NULL)
goto err;
- if ((v = OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL)
+ if ((v = OPENSSL_malloc(sizeof(*v))) == NULL)
goto err;
i = strlen(section) + 1;
if ((v->section = OPENSSL_malloc(i)) == NULL)
diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c
index 0ed06e11b8..8af2ab13ab 100644
--- a/crypto/conf/conf_def.c
+++ b/crypto/conf/conf_def.c
@@ -130,7 +130,7 @@ static CONF *def_create(CONF_METHOD *meth)
{
CONF *ret;
- ret = OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret)
if (meth->init(ret) == 0) {
OPENSSL_free(ret);
@@ -357,7 +357,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
p++;
*p = '\0';
- if (!(v = OPENSSL_malloc(sizeof(CONF_VALUE)))) {
+ if (!(v = OPENSSL_malloc(sizeof(*v)))) {
CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);
goto err;
}
diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c
index 18fe38b302..23d2a58e82 100644
--- a/crypto/conf/conf_mod.c
+++ b/crypto/conf/conf_mod.c
@@ -281,7 +281,7 @@ static CONF_MODULE *module_add(DSO *dso, const char *name,
supported_modules = sk_CONF_MODULE_new_null();
if (supported_modules == NULL)
return NULL;
- tmod = OPENSSL_malloc(sizeof(CONF_MODULE));
+ tmod = OPENSSL_malloc(sizeof(*tmod));
if (tmod == NULL)
return NULL;
@@ -336,7 +336,7 @@ static int module_init(CONF_MODULE *pmod, char *name, char *value,
CONF_IMODULE *imod = NULL;
/* Otherwise add initialized module to list */
- imod = OPENSSL_malloc(sizeof(CONF_IMODULE));
+ imod = OPENSSL_malloc(sizeof(*imod));
if (!imod)
goto err;