diff options
author | Rich Salz <rsalz@openssl.org> | 2016-11-15 18:54:28 -0500 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-11-15 19:03:18 -0500 |
commit | d18afb5bf29dc3b81b5f7a9eda2abde35041a441 (patch) | |
tree | 9c66c5792423c82d4710445ca21352042e8a0f42 /crypto/bn | |
parent | 18ad46297dcd44c1ac6c9f7f2f966e19c4d45e91 (diff) |
Check return value of some BN functions.
Factorise multiple bn_get_top(group->field) calls
Add missing checks on some conditional BN_copy return value
Add missing checks on some BN_copy return value
Add missing checks on a few bn_wexpand return value
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1626)
(cherry picked from commit 78e09b53a40729f5e99829ccc733b592bd22fea1)
Diffstat (limited to 'crypto/bn')
-rw-r--r-- | crypto/bn/bn_exp.c | 5 | ||||
-rw-r--r-- | crypto/bn/bn_mul.c | 5 | ||||
-rw-r--r-- | crypto/bn/bn_prime.c | 3 | ||||
-rw-r--r-- | crypto/bn/bn_sqr.c | 5 |
4 files changed, 11 insertions, 7 deletions
diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c index 61ab56d0df..feeb7649a5 100644 --- a/crypto/bn/bn_exp.c +++ b/crypto/bn/bn_exp.c @@ -78,8 +78,9 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) goto err; } } - if (r != rr) - BN_copy(r, rr); + if (r != rr && BN_copy(r, rr) == NULL) + goto err; + ret = 1; err: BN_CTX_end(ctx); diff --git a/crypto/bn/bn_mul.c b/crypto/bn/bn_mul.c index 1ff8efe39c..4c39d404b5 100644 --- a/crypto/bn/bn_mul.c +++ b/crypto/bn/bn_mul.c @@ -970,8 +970,9 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) end: #endif bn_correct_top(rr); - if (r != rr) - BN_copy(r, rr); + if (r != rr && BN_copy(r, rr) == NULL) + goto err; + ret = 1; err: bn_check_top(r); diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c index 51969583e7..7103acfe0b 100644 --- a/crypto/bn/bn_prime.c +++ b/crypto/bn/bn_prime.c @@ -240,7 +240,8 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BIGNUM *t; if ((t = BN_CTX_get(ctx)) == NULL) goto err; - BN_copy(t, a); + if (BN_copy(t, a) == NULL) + goto err; t->neg = 0; A = t; } else diff --git a/crypto/bn/bn_sqr.c b/crypto/bn/bn_sqr.c index a62bb1a584..44e7332acf 100644 --- a/crypto/bn/bn_sqr.c +++ b/crypto/bn/bn_sqr.c @@ -90,8 +90,9 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) rr->top = max - 1; else rr->top = max; - if (rr != r) - BN_copy(r, rr); + if (r != rr && BN_copy(r, rr) == NULL) + goto err; + ret = 1; err: bn_check_top(rr); |