Skip to content

Commit

Permalink
Merge pull request letscontrolit#3467 from aiolos/p1-buffer-overflow-fix
Browse files Browse the repository at this point in the history
Increase buffer size
  • Loading branch information
TD-er authored Jan 18, 2021
2 parents cdc8a1a + a5100e7 commit 584e3d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/src/PluginStructs/P044_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ void P044_Task::checkBlinkLED() {
}

void P044_Task::clearBuffer() {
if (serial_buffer.length() > maxMessageSize) {
maxMessageSize = serial_buffer.length();
}

serial_buffer = "";
serial_buffer.reserve(P044_DATAGRAM_MAX_SIZE);
serial_buffer.reserve(maxMessageSize);
}

void P044_Task::addChar(char ch) {
Expand All @@ -143,11 +147,11 @@ bool P044_Task::checkDatagram() const {

const int checksumStartIndex = endChar + 1;

if (PLUGIN_044_DEBUG) {
#ifdef PLUGIN_044_DEBUG
for (unsigned int cnt = 0; cnt < serial_buffer.length(); ++cnt) {
serialPrint(serial_buffer.substring(cnt, 1));
}
}
#endif

// calculate the CRC and check if it equals the hexadecimal one attached to the datagram
unsigned int crc = CRC16(serial_buffer, checksumStartIndex);
Expand Down Expand Up @@ -332,11 +336,11 @@ bool P044_Task::handleChar(char ch) {
// input is not a datagram char
addLog(LOG_LEVEL_DEBUG, F("P1 : Error: DATA corrupt, discarded input."));

if (PLUGIN_044_DEBUG) {
#ifdef PLUGIN_044_DEBUG
serialPrint(F("faulty char>"));
serialPrint(String(ch));
serialPrintln("<");
}
#endif
state = ParserState::WAITING; // reset
}

Expand Down
7 changes: 3 additions & 4 deletions src/src/PluginStructs/P044_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

#include <ESPeasySerial.h>

#ifndef PLUGIN_044_DEBUG
# define PLUGIN_044_DEBUG false // extra logging in serial out
#endif // ifndef PLUGIN_044_DEBUG
// #define PLUGIN_044_DEBUG // extra logging in serial out

#define P044_STATUS_LED 12
#define P044_CHECKSUM_LENGTH 4
#define P044_DATAGRAM_START_CHAR '/'
#define P044_DATAGRAM_END_CHAR '!'
#define P044_DATAGRAM_MAX_SIZE 1024
#define P044_DATAGRAM_MAX_SIZE 2048


struct P044_Task : public PluginTaskData_base {
Expand Down Expand Up @@ -97,6 +95,7 @@ struct P044_Task : public PluginTaskData_base {
boolean CRCcheck = false;
ESPeasySerial *P1EasySerial = nullptr;
unsigned long blinkLEDStartTime = 0;
size_t maxMessageSize = P044_DATAGRAM_MAX_SIZE / 4;
};

#endif
Expand Down

0 comments on commit 584e3d0

Please sign in to comment.