Skip to content

Commit d160571

Browse files
committed
Fix missing data when reading large values.
The wrong length value was being used to set the values read from peer attributes. This has been corrected to use the proper value size.
1 parent d8f0f66 commit d160571

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/NimBLERemoteCharacteristic.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,12 @@ int NimBLERemoteCharacteristic::onReadCB(uint16_t conn_handle,
551551

552552
if(rc == 0) {
553553
if(attr) {
554-
if(((*strBuf).length() + attr->om->om_len) > BLE_ATT_ATTR_MAX_LEN) {
554+
uint32_t data_len = OS_MBUF_PKTLEN(attr->om);
555+
if(((*strBuf).length() + data_len) > BLE_ATT_ATTR_MAX_LEN) {
555556
rc = BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
556557
} else {
557-
NIMBLE_LOGD(LOG_TAG, "Got %d bytes", attr->om->om_len);
558-
(*strBuf) += std::string((char*) attr->om->om_data, attr->om->om_len);
558+
NIMBLE_LOGD(LOG_TAG, "Got %d bytes", data_len);
559+
(*strBuf) += std::string((char*) attr->om->om_data, data_len);
559560
return 0;
560561
}
561562
}

src/NimBLERemoteDescriptor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ int NimBLERemoteDescriptor::onReadCB(uint16_t conn_handle,
203203

204204
if(rc == 0) {
205205
if(attr) {
206-
if(((*strBuf).length() + attr->om->om_len) > BLE_ATT_ATTR_MAX_LEN) {
206+
uint32_t data_len = OS_MBUF_PKTLEN(attr->om);
207+
if(((*strBuf).length() + data_len) > BLE_ATT_ATTR_MAX_LEN) {
207208
rc = BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
208209
} else {
209-
NIMBLE_LOGD(LOG_TAG, "Got %d bytes", attr->om->om_len);
210-
(*strBuf) += std::string((char*) attr->om->om_data, attr->om->om_len);
210+
NIMBLE_LOGD(LOG_TAG, "Got %d bytes", data_len);
211+
(*strBuf) += std::string((char*) attr->om->om_data, data_len);
211212
return 0;
212213
}
213214
}

0 commit comments

Comments
 (0)