Skip to content

Commit

Permalink
Prevent negative zero from being created via BN bit functions.
Browse files Browse the repository at this point in the history
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@
  • Loading branch information
4a6f656c committed Apr 15, 2024
1 parent ed75954 commit 7c058c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/libcrypto/bn/bn_lib.c
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7c058c6

Please sign in to comment.