Skip to content

Commit bfde89c

Browse files
sjancm-alperen-sener
authored andcommitted
[nrf fromtree] tests: Bluetooth: Tester: Improve BTP MTU validation
Make sure MTU is validated to avoid reading pass command buffer. Also make more explicit check in response length validation. Signed-off-by: Szymon Janc <[email protected]> (cherry picked from commit 24abac1)
1 parent a0078a6 commit bfde89c

File tree

1 file changed

+7
-5
lines changed
  • tests/bluetooth/tester/src

1 file changed

+7
-5
lines changed

tests/bluetooth/tester/src/btp.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,20 @@ static void cmd_handler(void *p1, void *p2, void *p3)
9090
struct btp_hdr *hdr;
9191
uint8_t status;
9292
uint16_t rsp_len = 0;
93-
uint16_t len;
9493

9594
cmd = k_fifo_get(&cmds_queue, K_FOREVER);
9695
hdr = (struct btp_hdr *)cmd->data;
9796

9897
LOG_DBG("cmd service 0x%02x opcode 0x%02x index 0x%02x",
9998
hdr->service, hdr->opcode, hdr->index);
10099

101-
len = sys_le16_to_cpu(hdr->len);
102-
103100
btp = find_btp_handler(hdr->service, hdr->opcode);
104101
if (btp) {
105-
if (btp->index != hdr->index) {
102+
uint16_t len = sys_le16_to_cpu(hdr->len);
103+
104+
if (len > BTP_DATA_MAX_SIZE) {
105+
status = BTP_STATUS_FAILED;
106+
} else if (btp->index != hdr->index) {
106107
status = BTP_STATUS_FAILED;
107108
} else if ((btp->expect_len >= 0) && (btp->expect_len != len)) {
108109
status = BTP_STATUS_FAILED;
@@ -111,7 +112,8 @@ static void cmd_handler(void *p1, void *p2, void *p3)
111112
cmd->rsp, &rsp_len);
112113
}
113114

114-
__ASSERT_NO_MSG((rsp_len + sizeof(struct btp_hdr)) <= BTP_MTU);
115+
/* This means that caller likely overwrote rsp buffer */
116+
__ASSERT_NO_MSG(rsp_len <= BTP_DATA_MAX_SIZE);
115117
} else {
116118
status = BTP_STATUS_UNKNOWN_CMD;
117119
}

0 commit comments

Comments
 (0)