diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2024-04-15 14:35:26 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2024-04-15 14:35:26 +0000 |
commit | 2ce4dfc1aba73de410dcee42cda06d35e7ebe981 (patch) | |
tree | 5bb43969504459263e90a764735c8184c425c52e | |
parent | 92ffdf62f0c7372c385f5fb5d38a9a95f8ce4d27 (diff) |
Prevent negative zero from being created via BN bit functions.
Both BN_clear_bit() and BN_mask_bits() can create zero values - in both
cases ensure that the negative sign is correctly handled if the value
becomes zero.
Thanks to Guido Vranken for providing a reproducer.
Fixes oss-fuzz #67901
ok tb@
-rw-r--r-- | lib/libcrypto/bn/bn_lib.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/libcrypto/bn/bn_lib.c b/lib/libcrypto/bn/bn_lib.c index c0c0ac876f4..b59e65a1e15 100644 --- a/lib/libcrypto/bn/bn_lib.c +++ b/lib/libcrypto/bn/bn_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_lib.c,v 1.90 2023/07/28 10:35:14 tb Exp $ */ +/* $OpenBSD: bn_lib.c,v 1.91 2024/04/15 14:35:25 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -438,6 +438,9 @@ BN_clear_bit(BIGNUM *a, int n) a->d[i] &= (~(((BN_ULONG)1) << j)); bn_correct_top(a); + + BN_set_negative(a, a->neg); + return (1); } LCRYPTO_ALIAS(BN_clear_bit); @@ -476,6 +479,9 @@ BN_mask_bits(BIGNUM *a, int n) a->d[w] &= ~(BN_MASK2 << b); } bn_correct_top(a); + + BN_set_negative(a, a->neg); + return (1); } LCRYPTO_ALIAS(BN_mask_bits); |