[esp32_ble_server] Fix incorrect BLECharacteristic read truncation (#16420) (#16422)

Co-authored-by: Dave <dave@morty>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
david-collett
2026-05-15 10:47:26 -07:00
committed by GitHub
co-authored by Dave pre-commit-ci-lite[bot]
parent 65d6bb18ed
commit fb70095ba1
@@ -218,13 +218,14 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
}
} else {
response.attr_value.offset = 0;
if (this->value_.size() + 1 > max_offset) {
response.attr_value.len = max_offset;
this->value_read_offset_ = max_offset;
} else {
response.attr_value.len = this->value_.size();
response.attr_value.len = this->value_.size();
if (response.attr_value.len > ESP_GATT_MAX_ATTR_LEN) {
ESP_LOGW(TAG, "Characteristic length %u exceeds buffer size of %u, truncating", response.attr_value.len,
ESP_GATT_MAX_ATTR_LEN);
response.attr_value.len = ESP_GATT_MAX_ATTR_LEN;
}
memcpy(response.attr_value.value, this->value_.data(), response.attr_value.len);
this->value_read_offset_ = 0;
}
response.attr_value.handle = this->handle_;