From dab9f8b55945a9ee34664c95fb94d4eade716339 Mon Sep 17 00:00:00 2001 From: JPZV <38300410+JPZV@users.noreply.github.com> Date: Mon, 29 May 2023 09:56:31 -0400 Subject: [PATCH] Fixed unhandled exception on handleGapEvent (#112) Somehow, the conn_handle can have the value of `0xffff`. Not sure why or how, but anyway it should be managed before moving forward on NimBLECharacteristic::handleGapEvent. Otherwise, an unhandled exception will occur on `assert(rc == 0);` --- src/NimBLECharacteristic.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/NimBLECharacteristic.cpp b/src/NimBLECharacteristic.cpp index 03d8c55..6b24b47 100644 --- a/src/NimBLECharacteristic.cpp +++ b/src/NimBLECharacteristic.cpp @@ -261,6 +261,12 @@ int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_han struct ble_gatt_access_ctxt *ctxt, void *arg) { + if (conn_handle > BLE_HCI_LE_CONN_HANDLE_MAX) + { + NIMBLE_LOGW(LOG_TAG, "Conn_handle (%d) is above the maximum value (%d)", conn_handle, BLE_HCI_LE_CONN_HANDLE_MAX); + return BLE_ATT_ERR_INVALID_HANDLE; + } + const ble_uuid_t *uuid; int rc; struct ble_gap_conn_desc desc;