From 363923ba67a47c632e6f1706f636f6a5ce35c82f Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 27 Mar 2023 10:22:47 +0000 Subject: [PATCH] Convert BN_copy() with missing error checks to bn_copy() ok jsing --- lib/libcrypto/bn/bn_exp.c | 8 +++++--- lib/libcrypto/bn/bn_mul.c | 8 +++++--- lib/libcrypto/bn/bn_sqr.c | 8 +++++--- lib/libcrypto/rsa/rsa_gen.c | 5 +++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/libcrypto/bn/bn_exp.c b/lib/libcrypto/bn/bn_exp.c index 4944daa48c0..b756d2b3056 100644 --- a/lib/libcrypto/bn/bn_exp.c +++ b/lib/libcrypto/bn/bn_exp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_exp.c,v 1.42 2023/03/27 10:21:23 tb Exp $ */ +/* $OpenBSD: bn_exp.c,v 1.43 2023/03/27 10:22:47 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -165,8 +165,10 @@ BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) ret = 1; err: - if (r != rr && rr != NULL) - BN_copy(r, rr); + if (r != rr && rr != NULL) { + if (!bn_copy(r, rr)) + ret = 0; + } BN_CTX_end(ctx); return (ret); } diff --git a/lib/libcrypto/bn/bn_mul.c b/lib/libcrypto/bn/bn_mul.c index 5e270b988f3..3a33767a935 100644 --- a/lib/libcrypto/bn/bn_mul.c +++ b/lib/libcrypto/bn/bn_mul.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mul.c,v 1.34 2023/02/22 05:57:19 jsing Exp $ */ +/* $OpenBSD: bn_mul.c,v 1.35 2023/03/27 10:22:47 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -786,8 +786,10 @@ BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) BN_set_negative(rr, a->neg ^ b->neg); - if (r != rr) - BN_copy(r, rr); + if (r != rr) { + if (!bn_copy(r, rr)) + goto err; + } done: ret = 1; err: diff --git a/lib/libcrypto/bn/bn_sqr.c b/lib/libcrypto/bn/bn_sqr.c index 6e784541bde..6641b77592d 100644 --- a/lib/libcrypto/bn/bn_sqr.c +++ b/lib/libcrypto/bn/bn_sqr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_sqr.c,v 1.27 2023/02/17 05:13:34 jsing Exp $ */ +/* $OpenBSD: bn_sqr.c,v 1.28 2023/03/27 10:22:47 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -404,8 +404,10 @@ BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) rr->neg = 0; - if (rr != r) - BN_copy(r, rr); + if (rr != r) { + if (!bn_copy(r, rr)) + goto err; + } done: ret = 1; diff --git a/lib/libcrypto/rsa/rsa_gen.c b/lib/libcrypto/rsa/rsa_gen.c index 7aefa7301c9..d4a4d60a86e 100644 --- a/lib/libcrypto/rsa/rsa_gen.c +++ b/lib/libcrypto/rsa/rsa_gen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsa_gen.c,v 1.26 2022/11/26 16:08:54 tb Exp $ */ +/* $OpenBSD: rsa_gen.c,v 1.27 2023/03/27 10:22:47 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -131,7 +131,8 @@ rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb) if (!rsa->iqmp && ((rsa->iqmp = BN_new()) == NULL)) goto err; - BN_copy(rsa->e, e_value); + if (!bn_copy(rsa->e, e_value)) + goto err; /* generate p and q */ for (;;) { -- 2.20.1