From b4faea50c35d92a67d1369355b49cc3efba78406 Mon Sep 17 00:00:00 2001 From: Rich Salz Date: Fri, 1 May 2015 23:10:31 -0400 Subject: 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 --- engines/ccgost/gost_pmeth.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/ccgost') diff --git a/engines/ccgost/gost_pmeth.c b/engines/ccgost/gost_pmeth.c index 416f0f986b..253757940d 100644 --- a/engines/ccgost/gost_pmeth.c +++ b/engines/ccgost/gost_pmeth.c @@ -24,7 +24,8 @@ static int pkey_gost_init(EVP_PKEY_CTX *ctx) { struct gost_pmeth_data *data; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); - data = OPENSSL_malloc(sizeof(struct gost_pmeth_data)); + + data = OPENSSL_malloc(sizeof(*data)); if (!data) return 0; memset(data, 0, sizeof(struct gost_pmeth_data)); @@ -406,8 +407,8 @@ static int pkey_gost_derive_init(EVP_PKEY_CTX *ctx) /* -------- PKEY_METHOD for GOST MAC algorithm --------------------*/ static int pkey_gost_mac_init(EVP_PKEY_CTX *ctx) { - struct gost_mac_pmeth_data *data; - data = OPENSSL_malloc(sizeof(struct gost_mac_pmeth_data)); + struct gost_mac_pmeth_data *data = OPENSSL_malloc(sizeof(*data)); + if (!data) return 0; memset(data, 0, sizeof(struct gost_mac_pmeth_data)); -- cgit v1.2.3