]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Depending on openssl version, base 64 decode is more or less strict
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 4 Feb 2026 12:21:23 +0000 (13:21 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 4 Feb 2026 13:45:21 +0000 (14:45 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/base64.cc
pdns/test-base64_cc.cc

index 5d3081b23f37a803dbcee29f1431c6cd48cdaeca..def6293a5a46775fcbeae4046987c52005145cfe 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include "base64.hh"
+#include <limits>
 #include <stdexcept>
 #include <boost/scoped_array.hpp>
 #include <openssl/bio.h>
@@ -86,7 +87,7 @@ std::string Base64Encode(const std::string& src)
     bio = BIO_push(b64, bio);
     BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
     int bioWriteRet = BIO_write(bio, src.c_str(), src.length());
-    if (bioWriteRet < 0 || (size_t)bioWriteRet != src.length()) {
+    if (bioWriteRet < 0 || static_cast<size_t>(bioWriteRet) != src.length()) {
       BIO_free_all(bio);
       throw std::runtime_error("BIO_write failed to write all data to memory buffer");
     }
index 01cae80d4d7d9dbfd11656232b592cb51b0b18ae..b09611b425794b21024ab428c3825ee10025c3ae 100644 (file)
@@ -8,6 +8,7 @@
 #include <boost/assign/std/map.hpp>
 
 #include "base64.hh"
+#include "openssl/conf.h"
 
 using namespace boost;
 
@@ -80,7 +81,13 @@ BOOST_AUTO_TEST_CASE(test_Base64_Decode_Garbage)
 {
   const std::string paddingOnly("====");
   std::string decoded;
-  BOOST_CHECK_EQUAL(B64Decode(paddingOnly, decoded), -1);
+  auto ret = B64Decode(paddingOnly, decoded);
+#if OPENSSL_VERSION_NUMBER >= 0x30500000
+  BOOST_CHECK_EQUAL(ret, -1);
+#else
+  // does not test anything meaningful, but avoids a "ret unused" warning
+  BOOST_CHECK(ret == 0 || ret == -1);
+#endif
 }
 
 BOOST_AUTO_TEST_SUITE_END()