From 2be9e7f8e4e4f96be340a8d78e337dc57c600c7a Mon Sep 17 00:00:00 2001 From: "Dr. Fred Nugen" Date: Mon, 4 Jul 2022 20:28:30 +0000 Subject: [PATCH] Fix buffer overflow introduced in #44. PR #44 introduced a buffer overflow bug that will corrupt the heap if the transmit payload size is increased after any send. --- src/MqttClient.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index f04fdd2..146e38f 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -802,6 +802,12 @@ void MqttClient::setConnectionTimeout(unsigned long timeout) void MqttClient::setTxPayloadSize(unsigned short size) { + if (_txPayloadBuffer) { + free(_txPayloadBuffer); + _txPayloadBuffer = NULL; + _txPayloadBufferIndex = 0; + } + _tx_payload_buffer_size = size; }