Skip to content

Commit 7e951d0

Browse files
Johan Hedberggmarull
authored andcommitted
[nrf fromtree] Bluetooth: host: Fix scan info dangling pointer
Clear pointer to the le_adv_recv() stack frame before returning to the calling function. This fixes a potential compiler warning newer gcc versions. zephyr/subsys/bluetooth/host/scan.c: In function ‘le_adv_recv’: zephyr/subsys/bluetooth/host/scan.c:463:20: error: storing the address of local variable ‘id_addr’ in ‘*info.addr’ [-Werror=dangling-pointer=] 463 | info->addr = &id_addr; | ~~~~~~~~~~~^~~~~~~~~~ zephyr/subsys/bluetooth/host/scan.c:439:22: note: ‘id_addr’ declared here 439 | bt_addr_le_t id_addr; | ^~~~~~~ Fixes #48459 Signed-off-by: Johan Hedberg <[email protected]> (cherry picked from commit 7ebaf1b) Signed-off-by: Herman Berget <[email protected]>
1 parent 42d8f92 commit 7e951d0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

subsys/bluetooth/host/scan.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
462462
bt_lookup_id_addr(BT_ID_DEFAULT, addr));
463463
}
464464

465-
info->addr = &id_addr;
466-
467465
if (scan_dev_found_cb) {
468466
net_buf_simple_save(buf, &state);
469467

@@ -473,6 +471,8 @@ static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
473471
net_buf_simple_restore(buf, &state);
474472
}
475473

474+
info->addr = &id_addr;
475+
476476
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&scan_cbs, listener, next, node) {
477477
if (listener->recv) {
478478
net_buf_simple_save(buf, &state);
@@ -484,6 +484,9 @@ static void le_adv_recv(bt_addr_le_t *addr, struct bt_le_scan_recv_info *info,
484484
}
485485
}
486486

487+
/* Clear pointer to this stack frame before returning to calling function */
488+
info->addr = NULL;
489+
487490
#if defined(CONFIG_BT_CENTRAL)
488491
check_pending_conn(&id_addr, addr, info->adv_props);
489492
#endif /* CONFIG_BT_CENTRAL */

0 commit comments

Comments
 (0)