diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-09-05 01:22:22 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-09-06 01:18:57 +0300 |
commit | bd96cc5bd58dabcff64975c91f12779e593b16fc (patch) | |
tree | 2c440ec399ff6446e83585c97e5919d67f801594 /src | |
parent | 2549b4753c78726677583d046fc8841c8f3e3577 (diff) | |
download | manaverse-bd96cc5bd58dabcff64975c91f12779e593b16fc.tar.gz manaverse-bd96cc5bd58dabcff64975c91f12779e593b16fc.tar.bz2 manaverse-bd96cc5bd58dabcff64975c91f12779e593b16fc.tar.xz manaverse-bd96cc5bd58dabcff64975c91f12779e593b16fc.zip |
Add checking for each packet size after reading and processed.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/messagein.cpp | 20 | ||||
-rw-r--r-- | src/net/messagein.h | 5 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 92447cde2..0c7f9cb7e 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -47,6 +47,26 @@ MessageIn::MessageIn(const char *const data, const unsigned int length) : DEBUGLOG("MessageIn"); } +MessageIn::~MessageIn() +{ + if (mLength) + { + if (mPos != mLength && mPos != 2) + { + logger->log("Wrong actual or planned inbound packet size!"); + logger->log(" packet id: %d 0x%x", + static_cast<int>(mId), + static_cast<int>(mId)); + logger->log(" planned size: %u", mLength); + logger->log(" read size: %u", mPos); + } + } + else + { + logger->log("Zero packet size: %d", static_cast<int>(mId)); + } +} + unsigned char MessageIn::readUInt8(const char *const str) { unsigned char value = static_cast<unsigned char>(-1); diff --git a/src/net/messagein.h b/src/net/messagein.h index 708041c2c..cc32328cb 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -40,6 +40,8 @@ class MessageIn notfinal public: A_DELETE_COPY(MessageIn) + virtual ~MessageIn(); + /** * Returns the message ID. */ @@ -109,9 +111,6 @@ class MessageIn notfinal unsigned char *readBytes(int length, const char *const dstr = nullptr); - virtual ~MessageIn() - { } - static uint8_t fromServerDirection(const uint8_t serverDir) A_WARN_UNUSED; |