Check remaining-length encoding is valid
This commit is contained in:
@ -240,6 +240,12 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
|
||||
uint8_t start = 0;
|
||||
|
||||
do {
|
||||
if (len == 6) {
|
||||
// Invalid remaining length encoding - kill the connection
|
||||
_state = MQTT_DISCONNECTED;
|
||||
_client->stop();
|
||||
return 0;
|
||||
}
|
||||
if(!readByte(&digit)) return 0;
|
||||
buffer[len++] = digit;
|
||||
length += (digit & 127) * multiplier;
|
||||
@ -335,6 +341,9 @@ boolean PubSubClient::loop() {
|
||||
} else if (type == MQTTPINGRESP) {
|
||||
pingOutstanding = false;
|
||||
}
|
||||
} else if (!connected()) {
|
||||
// readPacket has closed the connection
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user