summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-02-25 19:00:43 +0000
committerChristian Pointner <equinox@anytun.org>2008-02-25 19:00:43 +0000
commit619dec51f630116843a7d83c0c085abc7e3da688 (patch)
tree89536dff865336963d12ae7a3a5292509616c126
parentbugfix with packet length (diff)
fixed resize issue with buffer->xPacket
-rw-r--r--buffer.cpp2
-rw-r--r--buffer.h2
-rw-r--r--encryptedPacket.cpp9
-rw-r--r--encryptedPacket.h2
-rw-r--r--plainPacket.cpp7
-rw-r--r--plainPacket.h2
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<struct HeaderStruct*>(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<payload_type_t*>(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_;
};