Fix BN_CTX usage in BN_mod_sqrt malloc error paths. Bug: 442 Change-Id: I925eb8d4c4e60dd58d8aaf6010df9783e6ba0837 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/49825 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/fipsmodule/bn/sqrt.c b/crypto/fipsmodule/bn/sqrt.c index 23417d1..db88829 100644 --- a/crypto/fipsmodule/bn/sqrt.c +++ b/crypto/fipsmodule/bn/sqrt.c
@@ -75,10 +75,8 @@ if (ret == NULL) { ret = BN_new(); } - if (ret == NULL) { - goto end; - } - if (!BN_set_word(ret, BN_is_bit_set(a, 0))) { + if (ret == NULL || + !BN_set_word(ret, BN_is_bit_set(a, 0))) { if (ret != in) { BN_free(ret); } @@ -88,17 +86,15 @@ } OPENSSL_PUT_ERROR(BN, BN_R_P_IS_NOT_PRIME); - return (NULL); + return NULL; } if (BN_is_zero(a) || BN_is_one(a)) { if (ret == NULL) { ret = BN_new(); } - if (ret == NULL) { - goto end; - } - if (!BN_set_word(ret, BN_is_one(a))) { + if (ret == NULL || + !BN_set_word(ret, BN_is_one(a))) { if (ret != in) { BN_free(ret); }