summaryrefslogtreecommitdiffstats
path: root/crypto/bn
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/bn
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/bn')
-rw-r--r--crypto/bn/Makefile14
-rw-r--r--crypto/bn/bn_blind.c2
-rw-r--r--crypto/bn/bn_ctx.c4
-rw-r--r--crypto/bn/bn_gf2m.c10
-rw-r--r--crypto/bn/bn_lib.c6
-rw-r--r--crypto/bn/bn_mont.c2
-rw-r--r--crypto/bn/bn_recp.c2
7 files changed, 20 insertions, 20 deletions
diff --git a/crypto/bn/Makefile b/crypto/bn/Makefile
index 5b45f11851..2bae4abd8d 100644
--- a/crypto/bn/Makefile
+++ b/crypto/bn/Makefile
@@ -215,7 +215,7 @@ bn_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
bn_depr.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
bn_depr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bn_depr.o: ../cryptlib.h ../include/internal/bn_int.h bn_depr.c bn_lcl.h
-bn_dh.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
+bn_dh.o: ../../e_os.h ../../include/openssl/bn.h ../../include/openssl/crypto.h
bn_dh.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
bn_dh.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
bn_dh.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
@@ -391,12 +391,12 @@ bn_sqrt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
bn_sqrt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
bn_sqrt.o: ../../include/openssl/symhacks.h ../cryptlib.h
bn_sqrt.o: ../include/internal/bn_int.h bn_lcl.h bn_sqrt.c
-bn_srp.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-bn_srp.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
-bn_srp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-bn_srp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-bn_srp.o: ../../include/openssl/symhacks.h ../include/internal/bn_int.h
-bn_srp.o: bn_lcl.h bn_srp.c
+bn_srp.o: ../../e_os.h ../../include/openssl/bn.h
+bn_srp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+bn_srp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
+bn_srp.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
+bn_srp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
+bn_srp.o: ../include/internal/bn_int.h bn_lcl.h bn_srp.c
bn_word.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
bn_word.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
diff --git a/crypto/bn/bn_blind.c b/crypto/bn/bn_blind.c
index 659638bc45..9338cdd4c3 100644
--- a/crypto/bn/bn_blind.c
+++ b/crypto/bn/bn_blind.c
@@ -137,7 +137,7 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
bn_check_top(mod);
- if ((ret = OPENSSL_malloc(sizeof(BN_BLINDING))) == NULL) {
+ if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c
index d2dd1e6763..481c9d2496 100644
--- a/crypto/bn/bn_ctx.c
+++ b/crypto/bn/bn_ctx.c
@@ -186,7 +186,7 @@ static void ctxdbg(BN_CTX *ctx)
BN_CTX *BN_CTX_new(void)
{
- BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));
+ BN_CTX *ret = OPENSSL_malloc(sizeof(*ret));
if (!ret) {
BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
@@ -353,7 +353,7 @@ static BIGNUM *BN_POOL_get(BN_POOL *p)
if (p->used == p->size) {
BIGNUM *bn;
unsigned int loop = 0;
- BN_POOL_ITEM *item = OPENSSL_malloc(sizeof(BN_POOL_ITEM));
+ BN_POOL_ITEM *item = OPENSSL_malloc(sizeof(*item));
if (!item)
return NULL;
/* Initialise the structure */
diff --git a/crypto/bn/bn_gf2m.c b/crypto/bn/bn_gf2m.c
index c87c5d96f8..50d7c74085 100644
--- a/crypto/bn/bn_gf2m.c
+++ b/crypto/bn/bn_gf2m.c
@@ -551,7 +551,7 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
bn_check_top(a);
bn_check_top(b);
bn_check_top(p);
- if ((arr = OPENSSL_malloc(sizeof(int) * max)) == NULL)
+ if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) {
@@ -609,7 +609,7 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
bn_check_top(a);
bn_check_top(p);
- if ((arr = OPENSSL_malloc(sizeof(int) * max)) == NULL)
+ if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) {
@@ -1025,7 +1025,7 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
bn_check_top(a);
bn_check_top(b);
bn_check_top(p);
- if ((arr = OPENSSL_malloc(sizeof(int) * max)) == NULL)
+ if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) {
@@ -1084,7 +1084,7 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
int *arr = NULL;
bn_check_top(a);
bn_check_top(p);
- if ((arr = OPENSSL_malloc(sizeof(int) * max)) == NULL)
+ if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) {
@@ -1214,7 +1214,7 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
int *arr = NULL;
bn_check_top(a);
bn_check_top(p);
- if ((arr = OPENSSL_malloc(sizeof(int) * max)) == NULL)
+ if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
goto err;
ret = BN_GF2m_poly2arr(p, arr, max);
if (!ret || ret > max) {
diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c
index 3e9ea8ef4c..6fc0e396bf 100644
--- a/crypto/bn/bn_lib.c
+++ b/crypto/bn/bn_lib.c
@@ -268,7 +268,7 @@ BIGNUM *BN_new(void)
{
BIGNUM *ret;
- if ((ret = OPENSSL_malloc(sizeof(BIGNUM))) == NULL) {
+ if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
@@ -299,7 +299,7 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
- a = A = OPENSSL_malloc(sizeof(BN_ULONG) * words);
+ a = A = OPENSSL_malloc(sizeof(*a) * words);
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
@@ -919,7 +919,7 @@ BN_GENCB *BN_GENCB_new(void)
{
BN_GENCB *ret;
- if ((ret = OPENSSL_malloc(sizeof(BN_GENCB))) == NULL) {
+ if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
BNerr(BN_F_BN_GENCB_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
diff --git a/crypto/bn/bn_mont.c b/crypto/bn/bn_mont.c
index f19910dc46..d07afccadb 100644
--- a/crypto/bn/bn_mont.c
+++ b/crypto/bn/bn_mont.c
@@ -314,7 +314,7 @@ BN_MONT_CTX *BN_MONT_CTX_new(void)
{
BN_MONT_CTX *ret;
- if ((ret = OPENSSL_malloc(sizeof(BN_MONT_CTX))) == NULL)
+ if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
return (NULL);
BN_MONT_CTX_init(ret);
diff --git a/crypto/bn/bn_recp.c b/crypto/bn/bn_recp.c
index ef1972b227..3ab486bf59 100644
--- a/crypto/bn/bn_recp.c
+++ b/crypto/bn/bn_recp.c
@@ -71,7 +71,7 @@ BN_RECP_CTX *BN_RECP_CTX_new(void)
{
BN_RECP_CTX *ret;
- if ((ret = OPENSSL_malloc(sizeof(BN_RECP_CTX))) == NULL)
+ if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
return (NULL);
BN_RECP_CTX_init(ret);