diff --git a/implementation/configuration/src/configuration_impl.cpp b/implementation/configuration/src/configuration_impl.cpp index 34fd34320..49d4cfcff 100644 --- a/implementation/configuration/src/configuration_impl.cpp +++ b/implementation/configuration/src/configuration_impl.cpp @@ -3453,7 +3453,7 @@ std::uint32_t configuration_impl::get_max_message_size_reliable(const std::strin return its_port->second; } } - return (max_reliable_message_size_ == 0) ? ((VSOMEIP_MAX_TCP_MESSAGE_SIZE == 0) ? MESSAGE_SIZE_UNLIMITED : VSOMEIP_MAX_TCP_MESSAGE_SIZE) + return (max_reliable_message_size_ == 0) ? ((VSOMEIP_MAX_TCP_MESSAGE_SIZE == 0) ? VSOMEIP_MAX_TCP_MESSAGE_SIZE_DEFAULT : VSOMEIP_MAX_TCP_MESSAGE_SIZE) : max_reliable_message_size_; } diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index b79f65df2..9e9199de0 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -677,7 +677,7 @@ void tcp_server_endpoint_impl::connection::receive_cbk(boost::system::error_code its_lock.unlock(); wait_until_sent(boost::asio::error::operation_aborted); return; - } else if (max_message_size_ != MESSAGE_SIZE_UNLIMITED && current_message_size > max_message_size_) { + } else if (current_message_size > max_message_size_) { recv_buffer_size_ = 0; recv_buffer_.resize(recv_buffer_size_initial_, 0x0); recv_buffer_.shrink_to_fit(); diff --git a/interface/vsomeip/defines.hpp b/interface/vsomeip/defines.hpp index 8307acbb9..3b688f99e 100644 --- a/interface/vsomeip/defines.hpp +++ b/interface/vsomeip/defines.hpp @@ -14,6 +14,12 @@ constexpr std::uint8_t VSOMEIP_PROTOCOL_VERSION = 0x1; constexpr std::size_t VSOMEIP_MAX_LOCAL_MESSAGE_SIZE = 0; // 0 = unlimited, if not specified otherwise via configuration file constexpr std::size_t VSOMEIP_MAX_TCP_MESSAGE_SIZE = 0; +// Safe default cap for TCP receive buffer when neither VSOMEIP_MAX_TCP_MESSAGE_SIZE +// nor the runtime "max-message-size-reliable" JSON option is set. Prevents unbounded +// heap growth from an attacker-supplied SOME/IP Length field (CWE-789, issue #1009). +// Operators who genuinely need larger messages should set max-message-size-reliable +// in their vsomeip configuration file. +constexpr std::uint32_t VSOMEIP_MAX_TCP_MESSAGE_SIZE_DEFAULT = 1048576U; // 1 MiB constexpr std::size_t VSOMEIP_MAX_UDP_MESSAGE_SIZE = 1416; constexpr std::size_t VSOMEIP_PACKET_SIZE = VSOMEIP_MAX_UDP_MESSAGE_SIZE;