# HG changeset patch # User Tommaso Pecorella # Date 1474305724 -7200 # Parent 84eddd69aa8b7ddcdf8c63430eb0ad7769dc098d Printing a packet can raise an assert diff --git a/src/internet/model/icmpv4.cc b/src/internet/model/icmpv4.cc --- a/src/internet/model/icmpv4.cc +++ b/src/internet/model/icmpv4.cc @@ -247,24 +247,26 @@ Icmpv4Echo::Deserialize (Buffer::Iterator start) { NS_LOG_FUNCTION (this << &start); + + uint32_t optionalPayloadSize = start.GetRemainingSize () -4; + NS_ASSERT (start.GetRemainingSize () >= 4); + m_identifier = start.ReadNtohU16 (); m_sequence = start.ReadNtohU16 (); - NS_ASSERT (start.GetSize () >= 4); - uint32_t size = start.GetSize () - 4; - if (size != m_dataSize) + if (optionalPayloadSize != m_dataSize) { delete [] m_data; - m_data = new uint8_t[size]; - m_dataSize = size; + m_data = new uint8_t[optionalPayloadSize]; + m_dataSize = optionalPayloadSize; } start.Read (m_data, m_dataSize); - return m_dataSize; + return m_dataSize+4; } void Icmpv4Echo::Print (std::ostream &os) const { NS_LOG_FUNCTION (this << &os); - os << "identifier=" << m_identifier << ", sequence=" << m_sequence; + os << "identifier=" << m_identifier << ", sequence=" << m_sequence << ", data size=" << m_dataSize; } diff --git a/src/network/model/buffer.cc b/src/network/model/buffer.cc --- a/src/network/model/buffer.cc +++ b/src/network/model/buffer.cc @@ -1161,6 +1161,13 @@ return m_dataEnd - m_dataStart; } +uint32_t +Buffer::Iterator::GetRemainingSize (void) const +{ + NS_LOG_FUNCTION (this); + return m_dataEnd - m_current; +} + std::string Buffer::Iterator::GetReadErrorMessage (void) const diff --git a/src/network/model/buffer.h b/src/network/model/buffer.h --- a/src/network/model/buffer.h +++ b/src/network/model/buffer.h @@ -376,6 +376,11 @@ */ uint32_t GetSize (void) const; + /** + * \returns the size left to read of the underlying buffer we are iterating + */ + uint32_t GetRemainingSize (void) const; + private: friend class Buffer; /**