Skip to content

Commit 0e4677a

Browse files
committed
removed test, leaving just the fix
1 parent 3217322 commit 0e4677a

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

src/MqttClient.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ MqttClient::MqttClient(Client* client) :
7070
_keepAliveInterval(60 * 1000L),
7171
_connectionTimeout(30 * 1000L),
7272
_tx_payload_buffer_size(TX_PAYLOAD_BUFFER_SIZE),
73-
_last_mallocd_size(0), // DEBUG NOOJ
7473
_connectError(MQTT_SUCCESS),
7574
_connected(false),
7675
_subscribeQos(0x00),
@@ -667,36 +666,6 @@ size_t MqttClient::write(const uint8_t *buf, size_t size)
667666

668667
if (_txPayloadBuffer == NULL) {
669668
_txPayloadBuffer = (uint8_t*)malloc(_tx_payload_buffer_size);
670-
_last_mallocd_size = _tx_payload_buffer_size; //DEBUG NOOJ
671-
}
672-
673-
if (_txPayloadBufferIndex + size > _last_mallocd_size) {
674-
log_e(
675-
"MqttClient::write() ERROR: BUFFER OVERFLOW: _last_mallocd_size = %d, total bytes being written = %d",
676-
_last_mallocd_size, _txPayloadBufferIndex + size
677-
);
678-
679-
/*
680-
* Working example of buffer overflow bug:
681-
*
682-
// make my_settings > 512 chars
683-
mqttClient.beginMessage(SETTINGS_TOPIC);
684-
mqttClient.print(my_settings); // prints first 256 chars of my_settings
685-
mqttClient.endMessage();
686-
687-
mqttClient.setTxPayloadSize(512);
688-
mqttClient.beginMessage(SETTINGS_TOPIC);
689-
mqttClient.print(my_settings); // heap corruption
690-
mqttClient.endMessage();
691-
692-
// output
693-
[V][ssl_client.cpp:295] send_ssl_data(): Writing HTTP request with 17 bytes...
694-
[V][ssl_client.cpp:295] send_ssl_data(): Writing HTTP request with 256 bytes...
695-
[I][MqttClient.cpp:815] setTxPayloadSize(): MqttClient::setTxPayloadSize(): NOOJ says: _txPayloadBuffer should be freed and NULLed here.
696-
[E][MqttClient.cpp:677] write(): MqttClient::write() ERROR: BUFFER OVERFLOW: _last_mallocd_size = 256, total bytes being written = 512
697-
CORRUPT HEAP: multi_heap.c:432 detected at 0x3ffd6ab4
698-
abort() was called at PC 0x4008d447 on core 1
699-
*/
700669
}
701670

702671
memcpy(&_txPayloadBuffer[_txPayloadBufferIndex], buf, size);
@@ -833,16 +802,10 @@ void MqttClient::setConnectionTimeout(unsigned long timeout)
833802

834803
void MqttClient::setTxPayloadSize(unsigned short size)
835804
{
836-
// NOOJ WAS HERE
837-
log_i("MqttClient::setTxPayloadSize(): NOOJ says: _txPayloadBuffer should be freed and NULLed here.");
838-
839-
// TODO: Be clever and try to preserve existing _txPayloadBuffer contents?
840-
// TODO: Check if this messes up the state of pending messages
841805
if (_txPayloadBuffer) {
842806
free(_txPayloadBuffer);
843807
_txPayloadBuffer = NULL;
844808
_txPayloadBufferIndex = 0;
845-
_last_mallocd_size = 0;
846809
}
847810

848811
_tx_payload_buffer_size = size;

0 commit comments

Comments
 (0)