Commit f255c526594a2836c726d1b7a1cfefda746a6511
1 parent
d125dc49
Don't handle packets from clients we're closing
This should prevent stale data from old clients from manipulating the session.
Showing
2 changed files
with
6 additions
and
0 deletions
client.h
| ... | ... | @@ -134,6 +134,7 @@ public: |
| 134 | 134 | int writeMqttPacketAndBlameThisClient(PublishCopyFactory ©Factory, char max_qos, uint16_t packet_id); |
| 135 | 135 | int writeMqttPacketAndBlameThisClient(const MqttPacket &packet); |
| 136 | 136 | bool writeBufIntoFd(); |
| 137 | + bool isBeingDisconnected() const { return disconnectWhenBytesWritten; } | |
| 137 | 138 | bool readyForDisconnecting() const { return disconnectWhenBytesWritten && writebuf.usedBytes() == 0; } |
| 138 | 139 | |
| 139 | 140 | // Do this before calling an action that makes this client ready for writing, so that the EPOLLOUT will handle it. | ... | ... |
mqttpacket.cpp
| ... | ... | @@ -268,6 +268,11 @@ void MqttPacket::bufferToMqttPackets(CirBuf &buf, std::vector<MqttPacket> &packe |
| 268 | 268 | |
| 269 | 269 | void MqttPacket::handle() |
| 270 | 270 | { |
| 271 | + // It may be a stale client. This is especially important for when a session is picked up by another client. The old client | |
| 272 | + // may still have stale data in the buffer, causing action on the session otherwise. | |
| 273 | + if (sender->isBeingDisconnected()) | |
| 274 | + return; | |
| 275 | + | |
| 271 | 276 | if (packetType == PacketType::Reserved) |
| 272 | 277 | throw ProtocolError("Packet type 0 specified, which is reserved and invalid.", ReasonCodes::MalformedPacket); |
| 273 | 278 | ... | ... |