Skip to content

Commit 6dda052

Browse files
fdanis-ossSasha Levin
authored and
Sasha Levin
committed
Bluetooth: Fix eir name length
[ Upstream commit 2ab3e8d ] According to Section 1.2 of Core Specification Supplement Part A the complete or short name strings are defined as utf8s, which should not include the trailing NULL for variable length array as defined in Core Specification Vol1 Part E Section 2.9.3. Removing the trailing NULL allows PTS to retrieve the random address based on device name, e.g. for SM/PER/KDU/BV-02-C, SM/PER/KDU/BV-08-C or GAP/BROB/BCST/BV-03-C. Fixes: f61851f ("Bluetooth: Fix append max 11 bytes of name to scan rsp data") Signed-off-by: Frédéric Danis <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 9017a4f commit 6dda052

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

net/bluetooth/eir.c

+7-22
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,33 @@
1313

1414
#define PNP_INFO_SVCLASS_ID 0x1200
1515

16-
static u8 eir_append_name(u8 *eir, u16 eir_len, u8 type, u8 *data, u8 data_len)
17-
{
18-
u8 name[HCI_MAX_SHORT_NAME_LENGTH + 1];
19-
20-
/* If data is already NULL terminated just pass it directly */
21-
if (data[data_len - 1] == '\0')
22-
return eir_append_data(eir, eir_len, type, data, data_len);
23-
24-
memcpy(name, data, HCI_MAX_SHORT_NAME_LENGTH);
25-
name[HCI_MAX_SHORT_NAME_LENGTH] = '\0';
26-
27-
return eir_append_data(eir, eir_len, type, name, sizeof(name));
28-
}
29-
3016
u8 eir_append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len)
3117
{
3218
size_t short_len;
3319
size_t complete_len;
3420

35-
/* no space left for name (+ NULL + type + len) */
36-
if ((max_adv_len(hdev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 3)
21+
/* no space left for name (+ type + len) */
22+
if ((max_adv_len(hdev) - ad_len) < HCI_MAX_SHORT_NAME_LENGTH + 2)
3723
return ad_len;
3824

3925
/* use complete name if present and fits */
4026
complete_len = strnlen(hdev->dev_name, sizeof(hdev->dev_name));
4127
if (complete_len && complete_len <= HCI_MAX_SHORT_NAME_LENGTH)
42-
return eir_append_name(ptr, ad_len, EIR_NAME_COMPLETE,
43-
hdev->dev_name, complete_len + 1);
28+
return eir_append_data(ptr, ad_len, EIR_NAME_COMPLETE,
29+
hdev->dev_name, complete_len);
4430

4531
/* use short name if present */
4632
short_len = strnlen(hdev->short_name, sizeof(hdev->short_name));
4733
if (short_len)
48-
return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
34+
return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
4935
hdev->short_name,
50-
short_len == HCI_MAX_SHORT_NAME_LENGTH ?
51-
short_len : short_len + 1);
36+
short_len);
5237

5338
/* use shortened full name if present, we already know that name
5439
* is longer then HCI_MAX_SHORT_NAME_LENGTH
5540
*/
5641
if (complete_len)
57-
return eir_append_name(ptr, ad_len, EIR_NAME_SHORT,
42+
return eir_append_data(ptr, ad_len, EIR_NAME_SHORT,
5843
hdev->dev_name,
5944
HCI_MAX_SHORT_NAME_LENGTH);
6045

net/bluetooth/mgmt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -8400,7 +8400,7 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev,
84008400

84018401
static u8 calculate_name_len(struct hci_dev *hdev)
84028402
{
8403-
u8 buf[HCI_MAX_SHORT_NAME_LENGTH + 3];
8403+
u8 buf[HCI_MAX_SHORT_NAME_LENGTH + 2]; /* len + type + name */
84048404

84058405
return eir_append_local_name(hdev, buf, 0);
84068406
}

0 commit comments

Comments
 (0)