extmod/nimble: Fail read if the characteristic is too big.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2020-11-25 09:28:41 +11:00 committed by Damien George
parent b505971069
commit f2a9a0ac41
1 changed files with 5 additions and 1 deletions

View File

@ -608,7 +608,9 @@ static int characteristic_access_cb(uint16_t conn_handle, uint16_t value_handle,
return BLE_ATT_ERR_ATTR_NOT_FOUND;
}
os_mbuf_append(ctxt->om, entry->data, entry->data_len);
if (os_mbuf_append(ctxt->om, entry->data, entry->data_len)) {
return BLE_ATT_ERR_INSUFFICIENT_RES;
}
return 0;
case BLE_GATT_ACCESS_OP_WRITE_CHR:
@ -625,6 +627,8 @@ static int characteristic_access_cb(uint16_t conn_handle, uint16_t value_handle,
entry->data_len = MIN(entry->data_alloc, OS_MBUF_PKTLEN(ctxt->om) + offset);
os_mbuf_copydata(ctxt->om, 0, entry->data_len - offset, entry->data + offset);
// TODO: Consider failing with BLE_ATT_ERR_INSUFFICIENT_RES if the buffer is full.
mp_bluetooth_gatts_on_write(conn_handle, value_handle);
return 0;