From f255c526594a2836c726d1b7a1cfefda746a6511 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Thu, 21 Apr 2022 22:02:26 +0200 Subject: [PATCH] Don't handle packets from clients we're closing --- client.h | 1 + mqttpacket.cpp | 5 +++++ 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/client.h b/client.h index 4cc4061..bec5de8 100644 --- a/client.h +++ b/client.h @@ -134,6 +134,7 @@ public: int writeMqttPacketAndBlameThisClient(PublishCopyFactory ©Factory, char max_qos, uint16_t packet_id); int writeMqttPacketAndBlameThisClient(const MqttPacket &packet); bool writeBufIntoFd(); + bool isBeingDisconnected() const { return disconnectWhenBytesWritten; } bool readyForDisconnecting() const { return disconnectWhenBytesWritten && writebuf.usedBytes() == 0; } // Do this before calling an action that makes this client ready for writing, so that the EPOLLOUT will handle it. diff --git a/mqttpacket.cpp b/mqttpacket.cpp index 02aaf4a..f3ee26a 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -268,6 +268,11 @@ void MqttPacket::bufferToMqttPackets(CirBuf &buf, std::vector &packe void MqttPacket::handle() { + // It may be a stale client. This is especially important for when a session is picked up by another client. The old client + // may still have stale data in the buffer, causing action on the session otherwise. + if (sender->isBeingDisconnected()) + return; + if (packetType == PacketType::Reserved) throw ProtocolError("Packet type 0 specified, which is reserved and invalid.", ReasonCodes::MalformedPacket); -- libgit2 0.21.4