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>
diff --git a/ssl/ssl_conf.c b/ssl/ssl_conf.c
index 2d96b11..a14f564 100644
--- a/ssl/ssl_conf.c
+++ b/ssl/ssl_conf.c
@@ -609,9 +609,9 @@
SSL_CONF_CTX *SSL_CONF_CTX_new(void)
{
- SSL_CONF_CTX *ret;
+ SSL_CONF_CTX *ret = OPENSSL_malloc(sizeof(*ret));
size_t i;
- ret = OPENSSL_malloc(sizeof(SSL_CONF_CTX));
+
if (ret) {
ret->flags = 0;
ret->prefix = NULL;