Skip to content

Commit 8512bd1

Browse files
Thalleyfabiobaltieri
authored andcommitted
Bluetooth: Shell: Fix unintialized ad_len bug
`ad_len` was never initiatialized before we started incremetenting and using it. We would also override any user data in ad_init, which is fixed by using the length of the user data as an offset into the array. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 2ab1195 commit 8512bd1

File tree

1 file changed

+5
-2
lines changed
  • subsys/bluetooth/shell

1 file changed

+5
-2
lines changed

subsys/bluetooth/shell/bt.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
16421642
struct bt_data ad[9];
16431643
struct bt_data sd[9];
16441644
size_t hex_data_len;
1645-
size_t ad_len;
1645+
size_t ad_len = 0;
16461646
size_t sd_len = 0;
16471647
bool discoverable = false;
16481648
size_t *data_len;
@@ -1707,8 +1707,11 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
17071707
atomic_set_bit_to(adv_set_opt[selected_adv], SHELL_ADV_OPT_APPEARANCE,
17081708
appearance);
17091709

1710-
ad_len = ad_init(ad, ARRAY_SIZE(ad), adv_set_opt[selected_adv]);
1710+
ad_len = ad_init(&ad[*data_len], ARRAY_SIZE(ad) - *data_len,
1711+
adv_set_opt[selected_adv]);
17111712
if (ad_len < 0) {
1713+
shell_error(sh, "Failed to initialize stack advertising data");
1714+
17121715
return -ENOEXEC;
17131716
}
17141717

0 commit comments

Comments
 (0)