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/bio | |
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/bio')
-rw-r--r-- | crypto/bio/bf_buff.c | 3 | ||||
-rw-r--r-- | crypto/bio/bf_lbuf.c | 2 | ||||
-rw-r--r-- | crypto/bio/bf_nbio.c | 2 | ||||
-rw-r--r-- | crypto/bio/bio_lib.c | 3 | ||||
-rw-r--r-- | crypto/bio/bss_acpt.c | 2 | ||||
-rw-r--r-- | crypto/bio/bss_bio.c | 2 | ||||
-rw-r--r-- | crypto/bio/bss_conn.c | 2 | ||||
-rw-r--r-- | crypto/bio/bss_dgram.c | 4 |
8 files changed, 9 insertions, 11 deletions
diff --git a/crypto/bio/bf_buff.c b/crypto/bio/bf_buff.c index 53a120465a..6487f437d5 100644 --- a/crypto/bio/bf_buff.c +++ b/crypto/bio/bf_buff.c @@ -91,9 +91,8 @@ BIO_METHOD *BIO_f_buffer(void) static int buffer_new(BIO *bi) { - BIO_F_BUFFER_CTX *ctx; + BIO_F_BUFFER_CTX *ctx = OPENSSL_malloc(sizeof(*ctx)); - ctx = OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); if (ctx == NULL) return (0); ctx->ibuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE); diff --git a/crypto/bio/bf_lbuf.c b/crypto/bio/bf_lbuf.c index d7906b419c..e948e924b9 100644 --- a/crypto/bio/bf_lbuf.c +++ b/crypto/bio/bf_lbuf.c @@ -104,7 +104,7 @@ static int linebuffer_new(BIO *bi) { BIO_LINEBUFFER_CTX *ctx; - ctx = OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX)); + ctx = OPENSSL_malloc(sizeof(*ctx)); if (ctx == NULL) return (0); ctx->obuf = OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); diff --git a/crypto/bio/bf_nbio.c b/crypto/bio/bf_nbio.c index 9b9c0c08b2..53829ddac7 100644 --- a/crypto/bio/bf_nbio.c +++ b/crypto/bio/bf_nbio.c @@ -102,7 +102,7 @@ static int nbiof_new(BIO *bi) { NBIO_TEST *nt; - if (!(nt = OPENSSL_malloc(sizeof(NBIO_TEST)))) + if (!(nt = OPENSSL_malloc(sizeof(*nt)))) return (0); nt->lrn = -1; nt->lwn = -1; diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index e7957a7678..7542d1c885 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -65,9 +65,8 @@ BIO *BIO_new(BIO_METHOD *method) { - BIO *ret = NULL; + BIO *ret = OPENSSL_malloc(sizeof(*ret)); - ret = OPENSSL_malloc(sizeof(BIO)); if (ret == NULL) { BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); return (NULL); diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c index 6793fe17ac..cde8da3346 100644 --- a/crypto/bio/bss_acpt.c +++ b/crypto/bio/bss_acpt.c @@ -137,7 +137,7 @@ static BIO_ACCEPT *BIO_ACCEPT_new(void) { BIO_ACCEPT *ret; - if ((ret = OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL) + if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) return (NULL); memset(ret, 0, sizeof(BIO_ACCEPT)); diff --git a/crypto/bio/bss_bio.c b/crypto/bio/bss_bio.c index c9b8e7f1c6..afd2107234 100644 --- a/crypto/bio/bss_bio.c +++ b/crypto/bio/bss_bio.c @@ -144,7 +144,7 @@ static int bio_new(BIO *bio) { struct bio_bio_st *b; - b = OPENSSL_malloc(sizeof *b); + b = OPENSSL_malloc(sizeof(*b)); if (b == NULL) return 0; diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index 0b820820b8..b8fa8288eb 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -286,7 +286,7 @@ BIO_CONNECT *BIO_CONNECT_new(void) { BIO_CONNECT *ret; - if ((ret = OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) + if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) return (NULL); ret->state = BIO_CONN_S_BEFORE; ret->param_hostname = NULL; diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c index 406d46bb6c..fb1564cd12 100644 --- a/crypto/bio/bss_dgram.c +++ b/crypto/bio/bss_dgram.c @@ -225,7 +225,7 @@ static int dgram_new(BIO *bi) bi->init = 0; bi->num = 0; - data = OPENSSL_malloc(sizeof(bio_dgram_data)); + data = OPENSSL_malloc(sizeof(*data)); if (data == NULL) return 0; memset(data, 0x00, sizeof(bio_dgram_data)); @@ -1085,7 +1085,7 @@ static int dgram_sctp_new(BIO *bi) bi->init = 0; bi->num = 0; - data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); + data = OPENSSL_malloc(sizeof(*data)); if (data == NULL) return 0; memset(data, 0x00, sizeof(bio_dgram_sctp_data)); |