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


The following commit(s) were added to refs/heads/master by this push:
     new 9448c5f49 nimble/host: Fix NULL pointer dereference on invalid 
conn_handle
9448c5f49 is described below

commit 9448c5f495eb55018121b24a9dab5305c9222ea1
Author: Wiktor Kwiatkowski <[email protected]>
AuthorDate: Fri May 8 15:55:33 2026 +0200

    nimble/host: Fix NULL pointer dereference on invalid conn_handle
    
    Added a check to verify if the connection object is not NULL.
    This prevents a crash when debug assertions are disabled.
---
 nimble/host/src/ble_sm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c
index 79b321753..c2fac2553 100644
--- a/nimble/host/src/ble_sm.c
+++ b/nimble/host/src/ble_sm.c
@@ -1367,6 +1367,13 @@ ble_sm_ltk_req_rx(const struct 
ble_hci_ev_le_subev_lt_key_req *ev)
     memset(&res, 0, sizeof res);
 
     ble_hs_lock();
+
+    conn = ble_hs_conn_find_assert(conn_handle);
+    if (conn == NULL) {
+        ble_hs_unlock();
+        return BLE_HS_ENOENT;
+    }
+
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, 0, NULL);
     if (proc == NULL) {
         /* The peer is attempting to restore a encrypted connection via the
@@ -1406,7 +1413,6 @@ ble_sm_ltk_req_rx(const struct 
ble_hci_ev_le_subev_lt_key_req *ev)
     }
 
     if (restore) {
-        conn = ble_hs_conn_find_assert(conn_handle);
         ble_hs_conn_addrs(conn, &addrs);
         memcpy(peer_id_addr, addrs.peer_id_addr.val, 6);
     }

Reply via email to