diff options
author | David Benjamin <davidben@chromium.org> | 2015-06-12 04:42:14 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-06-15 20:52:40 +0300 |
commit | 1c703cb0c1e73d49af6bc837a7442f06a3dbcf08 (patch) | |
tree | 074de75247d9f774e282d439e5a438f644ead8b4 /crypto/bn | |
parent | 3a9e1fba0e3bcf014caa2df143a70475068447dc (diff) |
Check for BN_copy failures.
BN_copy can fail on malloc failure. The case in crypto/rsa was causing the
malloc tests in all_tests.go to infinite loop.
Change-Id: Id5900512013fba9960444d78a8c056aa4314fb2d
Reviewed-on: https://boringssl-review.googlesource.com/5110
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/bn')
-rw-r--r-- | crypto/bn/exponentiation.c | 4 | ||||
-rw-r--r-- | crypto/bn/mul.c | 8 | ||||
-rw-r--r-- | crypto/bn/prime.c | 5 | ||||
-rw-r--r-- | crypto/bn/sqrt.c | 4 |
4 files changed, 10 insertions, 11 deletions
diff --git a/crypto/bn/exponentiation.c b/crypto/bn/exponentiation.c index d3063c9f..e0ea16e2 100644 --- a/crypto/bn/exponentiation.c +++ b/crypto/bn/exponentiation.c @@ -173,8 +173,8 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) { } } - if (r != rr) { - BN_copy(r, rr); + if (r != rr && !BN_copy(r, rr)) { + goto err; } ret = 1; diff --git a/crypto/bn/mul.c b/crypto/bn/mul.c index a17d766b..029a59e2 100644 --- a/crypto/bn/mul.c +++ b/crypto/bn/mul.c @@ -666,8 +666,8 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) { end: bn_correct_top(rr); - if (r != rr) { - BN_copy(r, rr); + if (r != rr && !BN_copy(r, rr)) { + goto err; } ret = 1; @@ -877,8 +877,8 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) { rr->top = max; } - if (rr != r) { - BN_copy(r, rr); + if (rr != r && !BN_copy(r, rr)) { + goto err; } ret = 1; diff --git a/crypto/bn/prime.c b/crypto/bn/prime.c index cf3afcfd..655b4a56 100644 --- a/crypto/bn/prime.c +++ b/crypto/bn/prime.c @@ -515,11 +515,10 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, /* A := abs(a) */ if (a->neg) { - BIGNUM *t; - if ((t = BN_CTX_get(ctx)) == NULL) { + BIGNUM *t = BN_CTX_get(ctx); + if (t == NULL || !BN_copy(t, a)) { goto err; } - BN_copy(t, a); t->neg = 0; A = t; } else { diff --git a/crypto/bn/sqrt.c b/crypto/bn/sqrt.c index e71a8181..75f810e5 100644 --- a/crypto/bn/sqrt.c +++ b/crypto/bn/sqrt.c @@ -497,8 +497,8 @@ int BN_sqrt(BIGNUM *out_sqrt, const BIGNUM *in, BN_CTX *ctx) { ok = 1; err: - if (ok && out_sqrt == in) { - BN_copy(out_sqrt, estimate); + if (ok && out_sqrt == in && !BN_copy(out_sqrt, estimate)) { + ok = 0; } BN_CTX_end(ctx); return ok; |