Skip to content

Commit 32bb554

Browse files
tniessenrichardlau
authored andcommitted
crypto: fix large DH generator validation
Unfortunately, `std::optional<>` implements `operator<` in such a way that this check will fail for very large generators. Since `bn_g` is unsigned, if its value does not fit into a single word, we can be certain that it is at least 2. By only checking the value if it does indeed fit into a word, the check correctly ignores very large generators. Signed-off-by: Tobias Nießen <tniessen@tnie.de> PR-URL: #64092 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 66f6ac0 commit 32bb554

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/crypto/crypto_dh.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void New(const FunctionCallbackInfo<Value>& args) {
196196
#endif
197197
return ThrowCryptoError(env, ERR_get_error(), "Invalid generator");
198198
}
199-
if (bn_g.getWord() < 2) {
199+
if (bn_g.getWord().has_value() && bn_g.getWord().value() < 2) {
200200
#ifndef OPENSSL_IS_BORINGSSL
201201
ERR_put_error(ERR_LIB_DH, 0, DH_R_BAD_GENERATOR, __FILE__, __LINE__);
202202
#else

0 commit comments

Comments
 (0)