Bluetooth.cpp array bounds fix

Eliminates accessing array out of it's bounds - below array first element in next line, where buffer[bufferIndex-13] is used. When bufferIndex would be less than 12, out of bounds memory access would occur.
This commit is contained in:
Risto
2021-04-05 18:43:31 +02:00
committed by GitHub
parent 60084d2c53
commit 4e926fcdab
+2
View File
@@ -159,6 +159,7 @@ void Bluetooth::appendTrainerByte(uint8_t data)
buffer[bufferIndex++] = data; buffer[bufferIndex++] = data;
// we check for "DisConnected", but the first byte could be altered (if received in state STATE_DATA_XOR) // we check for "DisConnected", but the first byte could be altered (if received in state STATE_DATA_XOR)
if (data == '\n') { if (data == '\n') {
if (bufferIndex >= 13) {
if (!strncmp((char *)&buffer[bufferIndex-13], "isConnected", 11)) { if (!strncmp((char *)&buffer[bufferIndex-13], "isConnected", 11)) {
BLUETOOTH_TRACE("BT< DisConnected" CRLF); BLUETOOTH_TRACE("BT< DisConnected" CRLF);
state = BLUETOOTH_STATE_DISCONNECTED; state = BLUETOOTH_STATE_DISCONNECTED;
@@ -168,6 +169,7 @@ void Bluetooth::appendTrainerByte(uint8_t data)
} }
} }
} }
}
void Bluetooth::processTrainerByte(uint8_t data) void Bluetooth::processTrainerByte(uint8_t data)
{ {