summaryrefslogtreecommitdiffstats
path: root/crypto/evp
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/evp
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/evp')
-rw-r--r--crypto/evp/bio_b64.c2
-rw-r--r--crypto/evp/bio_enc.c2
-rw-r--r--crypto/evp/bio_ok.c2
-rw-r--r--crypto/evp/digest.c8
-rw-r--r--crypto/evp/evp_enc.c4
-rw-r--r--crypto/evp/evp_pbe.c3
-rw-r--r--crypto/evp/p_lib.c2
-rw-r--r--crypto/evp/pmeth_lib.c7
8 files changed, 16 insertions, 14 deletions
diff --git a/crypto/evp/bio_b64.c b/crypto/evp/bio_b64.c
index fe772fc34f..6dc3bb10ce 100644
--- a/crypto/evp/bio_b64.c
+++ b/crypto/evp/bio_b64.c
@@ -115,7 +115,7 @@ static int b64_new(BIO *bi)
{
BIO_B64_CTX *ctx;
- ctx = OPENSSL_malloc(sizeof(BIO_B64_CTX));
+ ctx = OPENSSL_malloc(sizeof(*ctx));
if (ctx == NULL)
return (0);
diff --git a/crypto/evp/bio_enc.c b/crypto/evp/bio_enc.c
index 0afd8cc502..86a2dc5743 100644
--- a/crypto/evp/bio_enc.c
+++ b/crypto/evp/bio_enc.c
@@ -112,7 +112,7 @@ static int enc_new(BIO *bi)
{
BIO_ENC_CTX *ctx;
- ctx = OPENSSL_malloc(sizeof(BIO_ENC_CTX));
+ ctx = OPENSSL_malloc(sizeof(*ctx));
if (ctx == NULL)
return (0);
EVP_CIPHER_CTX_init(&ctx->cipher);
diff --git a/crypto/evp/bio_ok.c b/crypto/evp/bio_ok.c
index eced061447..9a65a9de12 100644
--- a/crypto/evp/bio_ok.c
+++ b/crypto/evp/bio_ok.c
@@ -176,7 +176,7 @@ static int ok_new(BIO *bi)
{
BIO_OK_CTX *ctx;
- ctx = OPENSSL_malloc(sizeof(BIO_OK_CTX));
+ ctx = OPENSSL_malloc(sizeof(*ctx));
if (ctx == NULL)
return (0);
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 043830d5ff..04ab3a09b9 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -119,12 +119,12 @@
void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
{
- memset(ctx, '\0', sizeof *ctx);
+ memset(ctx, '\0', sizeof(*ctx));
}
EVP_MD_CTX *EVP_MD_CTX_create(void)
{
- EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof *ctx);
+ EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
if (ctx)
EVP_MD_CTX_init(ctx);
@@ -281,7 +281,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
} else
tmp_buf = NULL;
EVP_MD_CTX_cleanup(out);
- memcpy(out, in, sizeof *out);
+ memcpy(out, in, sizeof(*out));
if (in->md_data && out->digest->ctx_size) {
if (tmp_buf)
@@ -360,7 +360,7 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
*/
ENGINE_finish(ctx->engine);
#endif
- memset(ctx, '\0', sizeof *ctx);
+ memset(ctx, '\0', sizeof(*ctx));
return 1;
}
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index c2387b9ace..4dfc1593e6 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -76,7 +76,7 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
{
- EVP_CIPHER_CTX *ctx = OPENSSL_malloc(sizeof *ctx);
+ EVP_CIPHER_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
if (ctx)
EVP_CIPHER_CTX_init(ctx);
return ctx;
@@ -619,7 +619,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
#endif
EVP_CIPHER_CTX_cleanup(out);
- memcpy(out, in, sizeof *out);
+ memcpy(out, in, sizeof(*out));
if (in->cipher_data && in->cipher->ctx_size) {
out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c
index 6128a73620..0f325076d4 100644
--- a/crypto/evp/evp_pbe.c
+++ b/crypto/evp/evp_pbe.c
@@ -226,9 +226,10 @@ int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid,
int md_nid, EVP_PBE_KEYGEN *keygen)
{
EVP_PBE_CTL *pbe_tmp;
+
if (!pbe_algs)
pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp);
- if (!(pbe_tmp = OPENSSL_malloc(sizeof(EVP_PBE_CTL)))) {
+ if (!(pbe_tmp = OPENSSL_malloc(sizeof(*pbe_tmp)))) {
EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, ERR_R_MALLOC_FAILURE);
return 0;
}
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c
index c163e47829..42ae5ae069 100644
--- a/crypto/evp/p_lib.c
+++ b/crypto/evp/p_lib.c
@@ -185,7 +185,7 @@ EVP_PKEY *EVP_PKEY_new(void)
{
EVP_PKEY *ret;
- ret = OPENSSL_malloc(sizeof(EVP_PKEY));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (ret == NULL) {
EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c
index b20a902ef7..397d342e18 100644
--- a/crypto/evp/pmeth_lib.c
+++ b/crypto/evp/pmeth_lib.c
@@ -165,7 +165,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
return NULL;
}
- ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
+ ret = OPENSSL_malloc(sizeof(*ret));
if (!ret) {
#ifndef OPENSSL_NO_ENGINE
if (e)
@@ -197,7 +197,8 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
EVP_PKEY_METHOD *EVP_PKEY_meth_new(int id, int flags)
{
EVP_PKEY_METHOD *pmeth;
- pmeth = OPENSSL_malloc(sizeof(EVP_PKEY_METHOD));
+
+ pmeth = OPENSSL_malloc(sizeof(*pmeth));
if (!pmeth)
return NULL;
@@ -313,7 +314,7 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
return 0;
}
#endif
- rctx = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
+ rctx = OPENSSL_malloc(sizeof(*rctx));
if (!rctx)
return NULL;