diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f8ef396a..0b1921ca2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,15 @@ cmake_minimum_required(VERSION 3.12) +# Set CMake policies to handle compatibility with older dependencies +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") + cmake_policy(SET CMP0144 NEW) +endif() + +# Set policy to handle older CMake requirements in dependencies +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.5") + cmake_policy(SET CMP0000 NEW) +endif() + if (PACKAGE_MANAGER) if(NOT PACKAGE_MANAGER MATCHES "^(hunter|vcpkg)$") message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set") @@ -16,10 +26,6 @@ else () endif () message(STATUS "Selected package manager: ${PACKAGE_MANAGER}") -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") - cmake_policy(SET CMP0144 NEW) -endif() - find_program(CCACHE_FOUND ccache) if (CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 6549e8f29..4b81bb6c9 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -15,6 +15,44 @@ # CMAKE_ARGS "CMAKE_VARIABLE=value" # ) +# Fix for Protobuf CMake compatibility issue with modern CMake versions +hunter_config( + Protobuf + VERSION 3.19.4-p0 + CMAKE_ARGS + CMAKE_POLICY_VERSION_MINIMUM=3.5 + protobuf_BUILD_TESTS=OFF + protobuf_BUILD_SHARED_LIBS=OFF + KEEP_PACKAGE_SOURCES +) + +# Fix for c-ares CMake compatibility issue with modern CMake versions +hunter_config( + c-ares + VERSION 1.14.0-p0 + CMAKE_ARGS + CMAKE_POLICY_VERSION_MINIMUM=3.5 + KEEP_PACKAGE_SOURCES +) + +# Fix for yaml-cpp CMake compatibility issue with modern CMake versions +hunter_config( + yaml-cpp + VERSION 0.6.2-0f9a586-p1 + CMAKE_ARGS + CMAKE_POLICY_VERSION_MINIMUM=3.5 + KEEP_PACKAGE_SOURCES +) + +# Fix for Boost.DI CMake compatibility issue with modern CMake versions +hunter_config( + Boost.DI + VERSION 1.1.0-p1 + CMAKE_ARGS + CMAKE_POLICY_VERSION_MINIMUM=3.5 + KEEP_PACKAGE_SOURCES +) + hunter_config( soralog VERSION 0.2.5 diff --git a/src/security/tls/tls_details.cpp b/src/security/tls/tls_details.cpp index 19e5e804b..c28c3ce92 100644 --- a/src/security/tls/tls_details.cpp +++ b/src/security/tls/tls_details.cpp @@ -165,9 +165,9 @@ namespace libp2p::security::tls_details { constexpr size_t prefix_size = sign_prefix.size(); size_t msg_len = prefix_size + cert_pub_key.size(); - uint8_t buf[msg_len]; // NOLINT - memcpy(buf, sign_prefix.data(), sign_prefix.size()); - memcpy(buf + sign_prefix.size(), // NOLINT + std::vector buf(msg_len); + memcpy(buf.data(), sign_prefix.data(), sign_prefix.size()); + memcpy(buf.data() + sign_prefix.size(), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) cert_pub_key.data(), cert_pub_key.size()); @@ -179,7 +179,7 @@ namespace libp2p::security::tls_details { return crypto::ed25519::Ed25519ProviderImpl{} // NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions) - .sign(BytesIn(buf, msg_len), pk_data) + .sign(BytesIn(buf.data(), msg_len), pk_data) .value(); } @@ -203,8 +203,8 @@ namespace libp2p::security::tls_details { void assignSerial(X509 *cert) { BIGNUM *bn = BN_new(); CLEANUP_PTR(bn, BN_free); - if (BN_pseudo_rand(bn, 64, 0, 0) == 0) { - throw std::runtime_error("BN_pseudo_rand failed"); + if (BN_rand(bn, 64, 0, 0) == 0) { + throw std::runtime_error("BN_rand failed"); } ASN1_INTEGER *rand_int = ASN1_INTEGER_new(); @@ -402,13 +402,13 @@ namespace libp2p::security::tls_details { constexpr size_t prefix_size = sign_prefix.size(); size_t msg_len = prefix_size + len; - uint8_t buf[msg_len]; // NOLINT - memcpy(buf, sign_prefix.data(), prefix_size); - uint8_t *b = buf + prefix_size; // NOLINT - i2d_PUBKEY(cert_pubkey, &b); + std::vector buf(msg_len); + memcpy(buf.data(), sign_prefix.data(), prefix_size); + uint8_t *buf_ptr = buf.data() + prefix_size; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + i2d_PUBKEY(cert_pubkey, &buf_ptr); auto verify_res = crypto::ed25519::Ed25519ProviderImpl{}.verify( - BytesIn(buf, buf + msg_len), // NOLINT + BytesIn(buf.data(), buf.data() + msg_len), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) signature, ed25519pkey); diff --git a/src/transport/tcp/tcp_transport.cpp b/src/transport/tcp/tcp_transport.cpp index 182c67caa..1cab0cfcc 100644 --- a/src/transport/tcp/tcp_transport.cpp +++ b/src/transport/tcp/tcp_transport.cpp @@ -21,10 +21,13 @@ namespace libp2p::transport { auto &[info, layers] = r.value(); auto conn = std::make_shared(*context_, layers); auto connect = - [=, - self{shared_from_this()}, + [self{shared_from_this()}, handler{std::move(handler)}, - layers = std::move(layers)]( + layers = std::move(layers), + conn, + address, + remoteId, + mux_config_ = mux_config_]( outcome::result r) mutable { if (not r) { @@ -32,7 +35,7 @@ namespace libp2p::transport { } conn->connect( r.value(), - [=, handler{std::move(handler)}, layers = std::move(layers)]( + [=, handler{std::move(handler)}, layers = std::move(layers), &conn, &address, &remoteId]( auto ec, auto &e) mutable { if (ec) { std::ignore = conn->close();