Skip to content

Commit 90367c8

Browse files
jhedbergkartben
authored andcommitted
Bluetooth: Host: Classic: Fix allocated PSM comparison
The code for checking for allocated BR/EDR PSMs was potentially resulting in an integer overflow, due to doing a <= UINT16_MAX (0xffff) comparison on a uint16_t variable. To avoid this, use a uint32_t variable internally. Signed-off-by: Johan Hedberg <[email protected]>
1 parent d308608 commit 90367c8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

subsys/bluetooth/host/classic/l2cap_br.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,10 @@ static void l2cap_br_conf_rsp(struct bt_l2cap_br *l2cap, uint8_t ident,
11551155

11561156
static int bt_l2cap_br_allocate_psm(uint16_t *psm)
11571157
{
1158-
static uint16_t allocated_psm = L2CAP_BR_PSM_DYN_START;
1158+
/* DYN_END is UINT16_MAX, so to be able to do a psm <= DYN_END comparison
1159+
* we need to use uint32_t as the type.
1160+
*/
1161+
static uint32_t allocated_psm = L2CAP_BR_PSM_DYN_START;
11591162

11601163
if (allocated_psm < L2CAP_BR_PSM_DYN_END) {
11611164
allocated_psm = allocated_psm + 1;
@@ -1174,13 +1177,13 @@ static int bt_l2cap_br_allocate_psm(uint16_t *psm)
11741177
continue;
11751178
}
11761179

1177-
if (l2cap_br_server_lookup_psm(allocated_psm)) {
1180+
if (l2cap_br_server_lookup_psm((uint16_t)allocated_psm)) {
11781181
LOG_DBG("PSM 0x%04x has been used", allocated_psm);
11791182
continue;
11801183
}
11811184

11821185
LOG_DBG("Allocated PSM 0x%04x for new server", allocated_psm);
1183-
*psm = allocated_psm;
1186+
*psm = (uint16_t)allocated_psm;
11841187
return 0;
11851188
}
11861189

0 commit comments

Comments
 (0)