From 4db4ef0d637f8f2dc30cf7dc525069d5f5306b88 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Wed, 30 Oct 2024 23:00:33 -0500 Subject: [PATCH] fix(OpenSSL): fuzz errors #4663 --- NetSSL_OpenSSL/src/Context.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/NetSSL_OpenSSL/src/Context.cpp b/NetSSL_OpenSSL/src/Context.cpp index 696bdb72ba..3c5e92f813 100644 --- a/NetSSL_OpenSSL/src/Context.cpp +++ b/NetSSL_OpenSSL/src/Context.cpp @@ -930,20 +930,25 @@ void Context::initDH(KeyDHGroup keyDHGroup, const std::string& dhParamsFile) BIGNUM* p = nullptr; BIGNUM* g = nullptr; - if (use2048Bits) + if (keyDHGroup == KEY_DH_GROUP_2048) { p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), 0); g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), 0); DH_set0_pqg(dh, p, 0, g); DH_set_length(dh, 256); } - else + else if (keyDHGroup == KEY_DH_GROUP_1024) { p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), 0); g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), 0); DH_set0_pqg(dh, p, 0, g); DH_set_length(dh, 160); } + else + { + throw Poco::NotImplementedException(Poco::format( + "DH Group: %d", static_cast(keyDHGroup))); + } if (!p || !g) { DH_free(dh); @@ -952,18 +957,22 @@ void Context::initDH(KeyDHGroup keyDHGroup, const std::string& dhParamsFile) #else // OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) - if (use2048Bits) + if (keyDHGroup == KEY_DH_GROUP_2048) { dh->p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), 0); dh->g = BN_bin2bn(dh2048_g, sizeof(dh2048_g), 0); dh->length = 256; } - else + else if (keyDHGroup == KEY_DH_GROUP_1024) { dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), 0); dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), 0); dh->length = 160; } + { + throw Poco::NotImplementedException(Poco::format( + "DH Group: %d", static_cast(keyDHGroup))); + } if ((!dh->p) || (!dh->g)) { DH_free(dh);