From 619dec51f630116843a7d83c0c085abc7e3da688 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 25 Feb 2008 19:00:43 +0000 Subject: fixed resize issue with buffer->xPacket --- buffer.cpp | 2 ++ buffer.h | 2 ++ encryptedPacket.cpp | 9 +++++++-- encryptedPacket.h | 2 ++ plainPacket.cpp | 7 ++++++- plainPacket.h | 2 ++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/buffer.cpp b/buffer.cpp index cea8d2c..91ad950 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -161,6 +161,8 @@ void Buffer::setLength(u_int32_t new_length) old_buf = &buf_[old_length]; std::memset(old_buf, 0, real_length_ - old_length); + + reinit(); } else length_ = new_length; diff --git a/buffer.h b/buffer.h index 063be91..df17953 100644 --- a/buffer.h +++ b/buffer.h @@ -61,6 +61,8 @@ public: operator u_int8_t*(); protected: + virtual void reinit() {}; + u_int8_t *buf_; u_int32_t length_; u_int32_t real_length_; diff --git a/encryptedPacket.cpp b/encryptedPacket.cpp index a3e5886..b618f99 100644 --- a/encryptedPacket.cpp +++ b/encryptedPacket.cpp @@ -113,8 +113,13 @@ u_int32_t EncryptedPacket::getPayloadLength() const void EncryptedPacket::setPayloadLength(u_int32_t payload_length) { Buffer::setLength(payload_length + sizeof(struct HeaderStruct)); - - // depending on allow_realloc buf_ may point to another address + // depending on allow_realloc buf_ may point to another address + // therefore in this case reinit() gets called by Buffer::setLength() +} + +void EncryptedPacket::reinit() +{ + Buffer::reinit(); header_ = reinterpret_cast(buf_); payload_ = buf_ + sizeof(struct HeaderStruct); // TODO: fix auth_tag stuff auth_tag_ = NULL; // TODO: fix auth_tag stuff diff --git a/encryptedPacket.h b/encryptedPacket.h index 0b934f6..bb143f9 100644 --- a/encryptedPacket.h +++ b/encryptedPacket.h @@ -125,6 +125,8 @@ private: EncryptedPacket(); EncryptedPacket(const EncryptedPacket &src); + void reinit(); + struct HeaderStruct { seq_nr_t seq_nr; diff --git a/plainPacket.cpp b/plainPacket.cpp index d6f2e5f..37c4338 100644 --- a/plainPacket.cpp +++ b/plainPacket.cpp @@ -65,8 +65,13 @@ u_int32_t PlainPacket::getPayloadLength() const void PlainPacket::setPayloadLength(u_int32_t payload_length) { Buffer::setLength(payload_length + sizeof(payload_type_t)); + // depending on allow_realloc buf_ may point to another address + // therefore in this case reinit() gets called by Buffer::setLength() +} - // depending on allow_realloc buf_ may point to another address +void PlainPacket::reinit() +{ + Buffer::reinit(); payload_type_ = reinterpret_cast(buf_); payload_ = buf_ + sizeof(payload_type_t); } diff --git a/plainPacket.h b/plainPacket.h index 54c387a..e44df32 100644 --- a/plainPacket.h +++ b/plainPacket.h @@ -90,6 +90,8 @@ private: PlainPacket(); PlainPacket(const PlainPacket &src); + void reinit(); + payload_type_t* payload_type_; u_int8_t* payload_; }; -- cgit v1.2.3