summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-02-15 22:23:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-02-15 22:23:48 +0300
commit9dd2b2549e4cdca7022c0850882e29a5a4db2e70 (patch)
tree20f0e0193cfe92542091ea63131b25563cfc4700
parent0c4fe6c29604d1665443efe16fc3ac158690e290 (diff)
fix for the eternal loop in packet analyzer
-rw-r--r--protocols/Discord/src/gateway.cpp15
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();
}
}