Skip to content

Commit 0b4cd70

Browse files
Flavio Ceolinjgl-meta
authored andcommitted
bt: mesh: shell: Fix possible buffer overflow
Fix possible overflow in rpr_scan_report. Signed-off-by: Flavio Ceolin <[email protected]> (cherry picked from commit ddd2bc9)
1 parent 06ca73d commit 0b4cd70

File tree

1 file changed

+19
-2
lines changed
  • subsys/bluetooth/mesh/shell

1 file changed

+19
-2
lines changed

subsys/bluetooth/mesh/shell/rpr.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,26 @@ static void rpr_scan_report(struct bt_mesh_rpr_cli *cli,
3838
uint8_t len, type;
3939
uint8_t data[31];
4040

41-
len = net_buf_simple_pull_u8(adv_data) - 1;
41+
len = net_buf_simple_pull_u8(adv_data);
42+
if (len == 0) {
43+
/* No data in this AD Structure. */
44+
continue;
45+
}
46+
47+
if (len > adv_data->len) {
48+
/* Malformed AD Structure. */
49+
break;
50+
}
51+
4252
type = net_buf_simple_pull_u8(adv_data);
43-
memcpy(data, net_buf_simple_pull_mem(adv_data, len), len);
53+
if ((--len) > 0) {
54+
uint8_t dlen;
55+
56+
/* Pull all length, but print only what fits into `data` array. */
57+
dlen = MIN(len, sizeof(data) - 1);
58+
memcpy(data, net_buf_simple_pull_mem(adv_data, len), dlen);
59+
len = dlen;
60+
}
4461
data[len] = '\0';
4562

4663
if (type == BT_DATA_URI) {

0 commit comments

Comments
 (0)