aboutsummaryrefslogtreecommitdiffstats
path: root/test
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 /test
parent8920a7cd04f43b1a090d0b0a8c9e16b94c6898d4 (diff)
downloadopenssl-b4faea50c35d92a67d1369355b49cc3efba78406.tar.gz
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 'test')
-rw-r--r--test/Makefile23
-rw-r--r--test/ecdsatest.c4
-rw-r--r--test/ectest.c4
-rw-r--r--test/evp_test.c10
4 files changed, 19 insertions, 22 deletions
diff --git a/test/Makefile b/test/Makefile
index 74fdf459eb..97837e1682 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -714,15 +714,15 @@ exptest.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
exptest.o: ../include/openssl/ossl_typ.h ../include/openssl/rand.h
exptest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
exptest.o: ../include/openssl/symhacks.h exptest.c
-gost2814789test.o: ../engines/ccgost/gost89.h ../include/openssl/asn1.h
-gost2814789test.o: ../include/openssl/bio.h ../include/openssl/buffer.h
-gost2814789test.o: ../include/openssl/conf.h ../include/openssl/crypto.h
-gost2814789test.o: ../include/openssl/e_os2.h ../include/openssl/ec.h
-gost2814789test.o: ../include/openssl/ecdh.h ../include/openssl/ecdsa.h
-gost2814789test.o: ../include/openssl/engine.h ../include/openssl/err.h
-gost2814789test.o: ../include/openssl/evp.h ../include/openssl/hmac.h
-gost2814789test.o: ../include/openssl/lhash.h ../include/openssl/obj_mac.h
-gost2814789test.o: ../include/openssl/objects.h
+gost2814789test.o: ../e_os.h ../engines/ccgost/gost89.h
+gost2814789test.o: ../include/openssl/asn1.h ../include/openssl/bio.h
+gost2814789test.o: ../include/openssl/buffer.h ../include/openssl/conf.h
+gost2814789test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
+gost2814789test.o: ../include/openssl/ec.h ../include/openssl/ecdh.h
+gost2814789test.o: ../include/openssl/ecdsa.h ../include/openssl/engine.h
+gost2814789test.o: ../include/openssl/err.h ../include/openssl/evp.h
+gost2814789test.o: ../include/openssl/hmac.h ../include/openssl/lhash.h
+gost2814789test.o: ../include/openssl/obj_mac.h ../include/openssl/objects.h
gost2814789test.o: ../include/openssl/opensslconf.h
gost2814789test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
gost2814789test.o: ../include/openssl/pkcs7.h ../include/openssl/safestack.h
@@ -760,7 +760,7 @@ hmactest.o: ../include/openssl/safestack.h ../include/openssl/stack.h
hmactest.o: ../include/openssl/symhacks.h hmactest.c
ideatest.o: ../e_os.h ../include/openssl/e_os2.h ../include/openssl/idea.h
ideatest.o: ../include/openssl/opensslconf.h ideatest.c
-igetest.o: ../include/openssl/aes.h ../include/openssl/crypto.h
+igetest.o: ../e_os.h ../include/openssl/aes.h ../include/openssl/crypto.h
igetest.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h
igetest.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
igetest.o: ../include/openssl/rand.h ../include/openssl/safestack.h
@@ -859,7 +859,8 @@ ssltest.o: ../include/openssl/symhacks.h ../include/openssl/tls1.h
ssltest.o: ../include/openssl/x509.h ../include/openssl/x509_vfy.h
ssltest.o: ../include/openssl/x509v3.h ../ssl/record/record.h ../ssl/ssl_locl.h
ssltest.o: ssltest.c
-testutil.o: testutil.c testutil.h
+testutil.o: ../e_os.h ../include/openssl/e_os2.h
+testutil.o: ../include/openssl/opensslconf.h testutil.c testutil.h
v3nametest.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
v3nametest.o: ../include/openssl/buffer.h ../include/openssl/conf.h
v3nametest.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
diff --git a/test/ecdsatest.c b/test/ecdsatest.c
index 6aeff25d32..377e2c5367 100644
--- a/test/ecdsatest.c
+++ b/test/ecdsatest.c
@@ -318,9 +318,7 @@ int test_builtin(BIO *out)
/* get a list of all internal curves */
crv_len = EC_get_builtin_curves(NULL, 0);
-
- curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
-
+ curves = OPENSSL_malloc(sizeof(*curves) * crv_len);
if (curves == NULL) {
BIO_printf(out, "malloc error\n");
goto builtin_err;
diff --git a/test/ectest.c b/test/ectest.c
index 4b15708020..f04812e0c0 100644
--- a/test/ectest.c
+++ b/test/ectest.c
@@ -1359,9 +1359,7 @@ static void internal_curve_test(void)
int ok = 1;
crv_len = EC_get_builtin_curves(NULL, 0);
-
- curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
-
+ curves = OPENSSL_malloc(sizeof(*curves) * crv_len);
if (curves == NULL)
return;
diff --git a/test/evp_test.c b/test/evp_test.c
index 4b5b9aa5e3..0bba27425d 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -400,7 +400,7 @@ static int process_test(struct evp_test *t, char *buf, int verbose)
fprintf(stderr, "Duplicate key %s\n", value);
return 0;
}
- key = OPENSSL_malloc(sizeof(struct key_list));
+ key = OPENSSL_malloc(sizeof(*key));
if (!key)
return 0;
key->name = BUF_strdup(value);
@@ -559,7 +559,7 @@ static int digest_test_init(struct evp_test *t, const char *alg)
}
return 0;
}
- mdat = OPENSSL_malloc(sizeof(struct digest_data));
+ mdat = OPENSSL_malloc(sizeof(*mdat));
mdat->digest = digest;
mdat->input = NULL;
mdat->output = NULL;
@@ -671,7 +671,7 @@ static int cipher_test_init(struct evp_test *t, const char *alg)
}
return 0;
}
- cdat = OPENSSL_malloc(sizeof(struct cipher_data));
+ cdat = OPENSSL_malloc(sizeof(*cdat));
cdat->cipher = cipher;
cdat->enc = -1;
cdat->key = NULL;
@@ -935,7 +935,7 @@ static int mac_test_init(struct evp_test *t, const char *alg)
else
return 0;
- mdat = OPENSSL_malloc(sizeof(struct mac_data));
+ mdat = OPENSSL_malloc(sizeof(*mdat));
mdat->type = type;
mdat->alg = NULL;
mdat->key = NULL;
@@ -1103,7 +1103,7 @@ static int pkey_test_init(struct evp_test *t, const char *name,
return 1;
}
- kdata = OPENSSL_malloc(sizeof(struct pkey_data));
+ kdata = OPENSSL_malloc(sizeof(*kdata));
if (!kdata) {
EVP_PKEY_free(pkey);
return 0;