Skip to content

Commit 0fe62c6

Browse files
joerchancarlescufi
authored andcommitted
Bluetooth: host: Fix bug in device name shortening handling
Fix bug in device name shortening handling leading to memory corruption. This is triggered by an underflow in the length field of the shortened name when set_data_len + 2 > set_data_len_max. Fixes: #27693 Signed-off-by: Joakim Andersson <[email protected]>
1 parent f332d51 commit 0fe62c6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6592,14 +6592,17 @@ static int set_data_add(uint8_t *set_data, uint8_t set_data_len_max,
65926592

65936593
/* Check if ad fit in the remaining buffer */
65946594
if ((set_data_len + len + 2) > set_data_len_max) {
6595-
len = set_data_len_max - (set_data_len + 2);
6595+
ssize_t shortened_len = set_data_len_max -
6596+
(set_data_len + 2);
65966597

6597-
if (type != BT_DATA_NAME_COMPLETE || !len) {
6598+
if (!(type == BT_DATA_NAME_COMPLETE &&
6599+
shortened_len > 0)) {
65986600
BT_ERR("Too big advertising data");
65996601
return -EINVAL;
66006602
}
66016603

66026604
type = BT_DATA_NAME_SHORTENED;
6605+
len = shortened_len;
66036606
}
66046607

66056608
set_data[set_data_len++] = len + 1;

0 commit comments

Comments
 (0)