Allow sloppy datapoint message length (#1982)

This allows datapoint update messages to be handled even if the overall
message is longer than required (likely that it contains trailing empty
bytes).

The specific type handling will read only the expected data lengths so
we only need to hard bail if we have too little data not too much.
This commit is contained in:
Trevor North 2021-09-22 12:29:05 +01:00 committed by GitHub
parent b20760c93c
commit e32722db70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -241,8 +241,10 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) {
size_t data_size = (buffer[2] << 8) + buffer[3];
const uint8_t *data = buffer + 4;
size_t data_len = len - 4;
if (data_size != data_len) {
ESP_LOGW(TAG, "Datapoint %u is not expected size (%zu != %zu)", datapoint.id, data_size, data_len);
if (data_size > data_len) {
ESP_LOGW(TAG, "Datapoint %u has extra bytes that will be ignored (%zu > %zu)", datapoint.id, data_size, data_len);
} else if (data_size < data_len) {
ESP_LOGW(TAG, "Datapoint %u is truncated and cannot be parsed (%zu < %zu)", datapoint.id, data_size, data_len);
return;
}
datapoint.len = data_len;