From 09dbe9fc036f2a573c288fd229287a214a83c134 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 14 Aug 2024 13:43:24 -0400 Subject: [PATCH] check option and packet length --- libi2pd/Streaming.cpp | 5 +++++ libi2pd/Streaming.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libi2pd/Streaming.cpp b/libi2pd/Streaming.cpp index d71e5d4b..917d0d80 100644 --- a/libi2pd/Streaming.cpp +++ b/libi2pd/Streaming.cpp @@ -297,6 +297,11 @@ namespace stream { const uint8_t * optionData = packet->GetOptionData (); size_t optionSize = packet->GetOptionSize (); + if (optionSize > packet->len) + { + LogPrint (eLogInfo, "Streaming: Invalid option size ", optionSize, " Discarded"); + return false; + } if (flags & PACKET_FLAG_DELAY_REQUESTED) { if (!m_IsAckSendScheduled) diff --git a/libi2pd/Streaming.h b/libi2pd/Streaming.h index 415f3df4..22dad0e3 100644 --- a/libi2pd/Streaming.h +++ b/libi2pd/Streaming.h @@ -78,7 +78,7 @@ namespace stream Packet (): len (0), offset (0), sendTime (0), resent (false) {}; uint8_t * GetBuffer () { return buf + offset; }; - size_t GetLength () const { return len - offset; }; + size_t GetLength () const { return len > offset ? len - offset : 0; }; uint32_t GetSendStreamID () const { return bufbe32toh (buf); }; uint32_t GetReceiveStreamID () const { return bufbe32toh (buf + 4); };