Skip to content

Commit 32160a2

Browse files
committed
[Bugfix] Fix corrupted remote attribute reads with chained mbufs.
Walk the mbuf chain instead of copying the full packet length from the first buffer.
1 parent 5ae2c43 commit 32160a2

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/NimBLERemoteValueAttribute.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,19 @@ int NimBLERemoteValueAttribute::onReadCB(uint16_t conn_handle, const ble_gatt_er
207207
rc = BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
208208
} else {
209209
NIMBLE_LOGD(LOG_TAG, "Got %u bytes", data_len);
210-
valBuf->append(attr->om->om_data, data_len);
211-
return 0;
210+
for (const os_mbuf* om = attr->om; om != nullptr; om = SLIST_NEXT(om, om_next)) {
211+
const size_t expectedSize = valBuf->size() + om->om_len;
212+
valBuf->append(om->om_data, om->om_len);
213+
214+
if (valBuf->size() != expectedSize) {
215+
rc = BLE_ATT_ERR_INSUFFICIENT_RES;
216+
break;
217+
}
218+
}
219+
220+
if (rc == 0) {
221+
return 0;
222+
}
212223
}
213224
}
214225
}

0 commit comments

Comments
 (0)