From 53bca255b8f2eee6c187ac7c2d0988d8c4f55a96 Mon Sep 17 00:00:00 2001 From: ruben Date: Fri, 3 Apr 2020 10:43:31 +0100 Subject: [PATCH] Fixed uint64_t->size_t warnings in 32 bits --- .../network_algorithms/impl/execute_generic.hpp | 15 ++++++++++++--- .../mysql/detail/protocol/impl/serialization.ipp | 13 ++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/boost/mysql/detail/network_algorithms/impl/execute_generic.hpp b/include/boost/mysql/detail/network_algorithms/impl/execute_generic.hpp index 317689eb..69a546e1 100644 --- a/include/boost/mysql/detail/network_algorithms/impl/execute_generic.hpp +++ b/include/boost/mysql/detail/network_algorithms/impl/execute_generic.hpp @@ -2,6 +2,7 @@ #define INCLUDE_MYSQL_IMPL_NETWORK_ALGORITHMS_READ_RESULTSET_HEAD_IPP_ #include +#include namespace boost { namespace mysql { @@ -13,7 +14,7 @@ class execute_processor deserialize_row_fn deserializer_; channel& channel_; bytestring buffer_; - std::uint64_t field_count_ {}; + std::size_t field_count_ {}; ok_packet ok_packet_; std::vector fields_; std::vector field_buffers_; @@ -66,9 +67,17 @@ public: err = deserialize_message(num_fields, ctx); if (err) return; + // For platforms where size_t is shorter than uint64_t, + // perform range check + if (num_fields.value > std::numeric_limits::max()) + { + err = make_error_code(errc::protocol_value_error); + return; + } + // Ensure we have fields, as field_count is indicative of // a resultset with fields - field_count_ = num_fields.value; + field_count_ = static_cast(num_fields.value); if (field_count_ == 0) { err = make_error_code(errc::protocol_value_error); @@ -118,7 +127,7 @@ public: auto& get_channel() { return channel_; } auto& get_buffer() { return buffer_; } - std::uint64_t field_count() const noexcept { return field_count_; } + std::size_t field_count() const noexcept { return field_count_; } }; } // detail diff --git a/include/boost/mysql/detail/protocol/impl/serialization.ipp b/include/boost/mysql/detail/protocol/impl/serialization.ipp index 1e8db7b4..addf8fbe 100644 --- a/include/boost/mysql/detail/protocol/impl/serialization.ipp +++ b/include/boost/mysql/detail/protocol/impl/serialization.ipp @@ -1,6 +1,8 @@ #ifndef INCLUDE_BOOST_MYSQL_DETAIL_PROTOCOL_IMPL_SERIALIZATION_IPP_ #define INCLUDE_BOOST_MYSQL_DETAIL_PROTOCOL_IMPL_SERIALIZATION_IPP_ +#include + namespace boost { namespace mysql { namespace detail { @@ -254,13 +256,18 @@ boost::mysql::detail::serialization_traits< { return err; } - if (!ctx.enough_size(length.value)) + if (length.value > std::numeric_limits::max()) + { + return errc::protocol_value_error; + } + auto len = static_cast(length.value); + if (!ctx.enough_size(len)) { return errc::incomplete_message; } - output.value = get_string(ctx.first(), length.value); - ctx.advance(length.value); + output.value = get_string(ctx.first(), len); + ctx.advance(len); return errc::ok; }