diff options
author | tb <> | 2022-04-20 13:32:34 +0000 |
---|---|---|
committer | tb <> | 2022-04-20 13:32:34 +0000 |
commit | d302da36794487884f0ddef84b70d4fa96fe193d (patch) | |
tree | 43cc3e3cda610db5d4d1a8c236e941b33bae3293 /src | |
parent | 7b67219c7bc10448e8d9afb3fa8b1617f0a8e1ef (diff) | |
download | openbsd-d302da36794487884f0ddef84b70d4fa96fe193d.tar.gz openbsd-d302da36794487884f0ddef84b70d4fa96fe193d.tar.bz2 openbsd-d302da36794487884f0ddef84b70d4fa96fe193d.zip |
Avoid use of uninitialized in BN_mod_exp_recp()
If either of the two initial BN_CTX_get() fails, we will call
BN_RECP_CTX_free() on the uninitialized recp, which won't end
well, so hoist the BN_RECP_CTX_init() call a few lines up.
From Pauli, OpenSSL ad249412
ok inoguchi jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/bn_exp.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c index b778d5d67c..3525b50388 100644 --- a/src/lib/libcrypto/bn/bn_exp.c +++ b/src/lib/libcrypto/bn/bn_exp.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_exp.c,v 1.31 2017/05/02 03:59:44 deraadt Exp $ */ | 1 | /* $OpenBSD: bn_exp.c,v 1.32 2022/04/20 13:32:34 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -278,13 +278,14 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | |||
278 | return ret; | 278 | return ret; |
279 | } | 279 | } |
280 | 280 | ||
281 | BN_RECP_CTX_init(&recp); | ||
282 | |||
281 | BN_CTX_start(ctx); | 283 | BN_CTX_start(ctx); |
282 | if ((aa = BN_CTX_get(ctx)) == NULL) | 284 | if ((aa = BN_CTX_get(ctx)) == NULL) |
283 | goto err; | 285 | goto err; |
284 | if ((val[0] = BN_CTX_get(ctx)) == NULL) | 286 | if ((val[0] = BN_CTX_get(ctx)) == NULL) |
285 | goto err; | 287 | goto err; |
286 | 288 | ||
287 | BN_RECP_CTX_init(&recp); | ||
288 | if (m->neg) { | 289 | if (m->neg) { |
289 | /* ignore sign of 'm' */ | 290 | /* ignore sign of 'm' */ |
290 | if (!BN_copy(aa, m)) | 291 | if (!BN_copy(aa, m)) |