diff options
author | George Hazan <ghazan@miranda.im> | 2017-02-15 22:23:35 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-02-15 22:23:48 +0300 |
commit | 9dd2b2549e4cdca7022c0850882e29a5a4db2e70 (patch) | |
tree | 20f0e0193cfe92542091ea63131b25563cfc4700 /protocols/Discord | |
parent | 0c4fe6c29604d1665443efe16fc3ac158690e290 (diff) |
fix for the eternal loop in packet analyzer
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/gateway.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index 9bb304d36f..6eca5b1fe9 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -239,6 +239,7 @@ void CDiscordProto::GatewayThreadWorker() } // read all payloads from the current buffer, one by one + size_t prevSize = 0; while (true) { switch (hdr.opCode) { case 0: // text packet @@ -271,8 +272,22 @@ void CDiscordProto::GatewayThreadWorker() if (netbuf.length() == 0) break; + // if we have not enough data for header, continue reading if (!hdr.init((BYTE*)netbuf.data(), netbuf.length())) break; + + // if we have not enough data for data, continue reading + if (hdr.headerSize + hdr.payloadSize > netbuf.length()) + break; + + debugLogA("Got inner packet: buffer = %d, opcode = %d, headerSize = %d, payloadSize = %d, final = %d, masked = %d", netbuf.length(), hdr.opCode, hdr.headerSize, hdr.payloadSize, hdr.bIsFinal, hdr.bIsMasked); + if (prevSize == netbuf.length()) { + netbuf.remove(prevSize); + debugLogA("dropping current packet, exiting"); + break; + } + + prevSize = netbuf.length(); } } |