From d0451399458314b5160aa8b139bd766ee82451db Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 16 Nov 2020 07:57:32 +0800 Subject: [PATCH] return ble errors for invalid values --- src/nimble/BluetoothUtil.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 8009f5d22..8a0dd779b 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -392,6 +392,7 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) } } + /** * A helper function that implements simple read and write handling for a uint32_t * @@ -415,6 +416,7 @@ int chr_readwrite32le(uint32_t *v, struct ble_gatt_access_ctxt *ctxt) if (len < sizeof(le)) { DEBUG_MSG("Error: wrongsized write32\n"); *v = 0; + return BLE_ATT_ERR_UNLIKELY; } else { *v = get_le32(le); DEBUG_MSG("BLE writing a uint32\n"); @@ -441,8 +443,10 @@ int chr_readwrite8(uint8_t *v, size_t vlen, struct ble_gatt_access_ctxt *ctxt) auto rc = ble_hs_mbuf_to_flat(ctxt->om, v, vlen, &len); assert(rc == 0); - if (len < vlen) + if (len < vlen) { DEBUG_MSG("Error: wrongsized write\n"); + return BLE_ATT_ERR_UNLIKELY; + } else { DEBUG_MSG("BLE writing bytes\n"); }