From 9d0847ae6dc2a54f2c673e82fe4ede2570923710 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Mon, 16 Feb 2015 03:57:55 -0500 Subject: Add some missing error failure checks. Found while diagnosing some crashes and hangs in the malloc tests. This (and the follow-up) get us further but does not quite let the malloc tests pass quietly, even without valgrind. DTLS silently ignores some malloc failures (confusion with silently dropping bad packets) which then translate to hangs. Change-Id: Ief06a671e0973d09d2883432b89a86259e346653 Reviewed-on: https://boringssl-review.googlesource.com/3482 Reviewed-by: Adam Langley --- crypto/bn/div.c | 4 +++- crypto/bn/gcd.c | 12 ++---------- 2 files changed, 5 insertions(+), 11 deletions(-) (limited to 'crypto') diff --git a/crypto/bn/div.c b/crypto/bn/div.c index 2bf86de7..8b0152e8 100644 --- a/crypto/bn/div.c +++ b/crypto/bn/div.c @@ -362,7 +362,9 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, * BN_rshift() will overwrite it. */ int neg = num->neg; - BN_rshift(rm, snum, norm_shift); + if (!BN_rshift(rm, snum, norm_shift)) { + goto err; + } if (!BN_is_zero(rm)) { rm->neg = neg; } diff --git a/crypto/bn/gcd.c b/crypto/bn/gcd.c index 789a0942..3132c29e 100644 --- a/crypto/bn/gcd.c +++ b/crypto/bn/gcd.c @@ -258,12 +258,8 @@ BIGNUM *BN_mod_inverse(BIGNUM *out, const BIGNUM *a, const BIGNUM *n, goto err; } - BN_one(X); BN_zero(Y); - if (BN_copy(B, a) == NULL) { - goto err; - } - if (BN_copy(A, n) == NULL) { + if (!BN_one(X) || BN_copy(B, a) == NULL || BN_copy(A, n) == NULL) { goto err; } A->neg = 0; @@ -570,12 +566,8 @@ static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *out, const BIGNUM *a, goto err; } - BN_one(X); BN_zero(Y); - if (BN_copy(B, a) == NULL) { - goto err; - } - if (BN_copy(A, n) == NULL) { + if (!BN_one(X) || BN_copy(B, a) == NULL || BN_copy(A, n) == NULL) { goto err; } A->neg = 0; -- cgit v1.2.3