This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit f6dfde3dc454ac79efe10c24f6926bb96fa3f54d
Author: Szymon Janc <[email protected]>
AuthorDate: Wed Oct 7 18:36:02 2026 +0200

    nimble/host: Fix EATT encryption check relying on assert
    
    Connection descriptor used for the EATT bearer encryption check was
    filled only inside assert(), so with asserts compiled out the check
    used an uninitialized descriptor. Call ble_gap_conn_find() outside of
    assert. Failing to find connection indicates internal error so assert
    on it, but also treat it as unencrypted link if asserts are disabled.
    
    Assisted-by: Claude:claude-opus-5-5
---
 nimble/host/src/ble_eatt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/nimble/host/src/ble_eatt.c b/nimble/host/src/ble_eatt.c
index 047a08764..0c8aefced 100644
--- a/nimble/host/src/ble_eatt.c
+++ b/nimble/host/src/ble_eatt.c
@@ -283,7 +283,8 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void 
*arg)
             return BLE_HS_EREJECT;
         }
 
-        assert (!ble_gap_conn_find(event->receive.conn_handle, &desc));
+        rc = ble_gap_conn_find(event->receive.conn_handle, &desc);
+        assert(rc == 0);
         /* As per BLE 5.4 Standard, Vol. 3, Part F, section 5.3.2
          * (ENHANCED ATT BEARER L2CAP INTEROPERABILITY REQUIREMENTS:
          * Channel Requirements):
@@ -292,7 +293,7 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void 
*arg)
          * Disconnect peer with invalid behavior - ATT PDU received before
          * encryption.
          */
-        if (!desc.sec_state.encrypted) {
+        if (rc != 0 || !desc.sec_state.encrypted) {
             ble_l2cap_disconnect(eatt->chan);
             return BLE_HS_EREJECT;
         }

Reply via email to