Skip to content

Commit e363dec

Browse files
a1ienMaureenHelm
authored andcommitted
Bluetooth: fix strncpy call in bt_set_name
In bt_set_name we already get name length so let's use it in strncpy Also fix warning with enable -Wstringop-truncation Signed-off-by: Ilya Averyanov <[email protected]>
1 parent 8825ce0 commit e363dec

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6723,20 +6723,21 @@ int bt_set_name(const char *name)
67236723
size_t len = strlen(name);
67246724
int err;
67256725

6726-
if (len >= sizeof(bt_dev.name)) {
6726+
if (len > CONFIG_BT_DEVICE_NAME_MAX) {
67276727
return -ENOMEM;
67286728
}
67296729

67306730
if (!strcmp(bt_dev.name, name)) {
67316731
return 0;
67326732
}
67336733

6734-
strncpy(bt_dev.name, name, sizeof(bt_dev.name));
6734+
strncpy(bt_dev.name, name, len);
6735+
bt_dev.name[len] = '\0';
67356736

67366737
/* Update advertising name if in use */
67376738
if (adv && atomic_test_bit(adv->flags, BT_ADV_INCLUDE_NAME)) {
67386739
struct bt_data data[] = { BT_DATA(BT_DATA_NAME_COMPLETE, name,
6739-
strlen(name)) };
6740+
len) };
67406741
struct bt_ad sd = { data, ARRAY_SIZE(data) };
67416742

67426743
set_sd(adv, &sd, 1);

0 commit comments

Comments
 (0)