diff options
author | David Benjamin <davidben@chromium.org> | 2015-05-16 02:11:57 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-05-21 21:00:10 +0300 |
commit | 3fa65f0f05f67615d9daf48940e07f84d094ac6e (patch) | |
tree | 9c4c6b56547b20c13098624e4442f1fad6941ffd /crypto/dsa | |
parent | 0b635c52b241af78b69addecbb84c7d55f3cabb4 (diff) |
Fix some malloc test crashs.
This isn't exhaustive. There are still failures in some tests which probably
ought to get C++'d first.
Change-Id: Iac58df9d98cdfd94603d54374a531b2559df64c3
Reviewed-on: https://boringssl-review.googlesource.com/4795
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/dsa')
-rw-r--r-- | crypto/dsa/dsa_impl.c | 10 | ||||
-rw-r--r-- | crypto/dsa/dsa_test.c | 6 |
2 files changed, 11 insertions, 5 deletions
diff --git a/crypto/dsa/dsa_impl.c b/crypto/dsa/dsa_impl.c index b7e1fd82..2ab8ba8b 100644 --- a/crypto/dsa/dsa_impl.c +++ b/crypto/dsa/dsa_impl.c @@ -501,12 +501,16 @@ static int paramgen(DSA *ret, unsigned bits, const uint8_t *seed_in, } ctx = BN_CTX_new(); + if (ctx == NULL) { + goto err; + } + BN_CTX_start(ctx); + mont = BN_MONT_CTX_new(); - if (ctx == NULL || mont == NULL) { + if (mont == NULL) { goto err; } - BN_CTX_start(ctx); r0 = BN_CTX_get(ctx); g = BN_CTX_get(ctx); W = BN_CTX_get(ctx); @@ -516,7 +520,7 @@ static int paramgen(DSA *ret, unsigned bits, const uint8_t *seed_in, p = BN_CTX_get(ctx); test = BN_CTX_get(ctx); - if (!BN_lshift(test, BN_value_one(), bits - 1)) { + if (test == NULL || !BN_lshift(test, BN_value_one(), bits - 1)) { goto err; } diff --git a/crypto/dsa/dsa_test.c b/crypto/dsa/dsa_test.c index 9b70dbee..8bdaaf44 100644 --- a/crypto/dsa/dsa_test.c +++ b/crypto/dsa/dsa_test.c @@ -238,8 +238,10 @@ static int test_generate(FILE *out) { goto end; } - DSA_generate_key(dsa); - DSA_sign(0, fips_digest, sizeof(fips_digest), sig, &siglen, dsa); + if (!DSA_generate_key(dsa) || + !DSA_sign(0, fips_digest, sizeof(fips_digest), sig, &siglen, dsa)) { + goto end; + } if (DSA_verify(0, fips_digest, sizeof(fips_digest), sig, siglen, dsa) == 1) { ok = 1; } else { |