Skip to content

Commit

Permalink
bt: mesh: shell: Fix possible buffer overflow
Browse files Browse the repository at this point in the history
Fix possible overflow in rpr_scan_report.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin authored and fabiobaltieri committed Jul 20, 2023
1 parent e55af04 commit ddd2bc9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions subsys/bluetooth/mesh/shell/rpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,26 @@ static void rpr_scan_report(struct bt_mesh_rpr_cli *cli,
uint8_t len, type;
uint8_t data[31];

len = net_buf_simple_pull_u8(adv_data) - 1;
len = net_buf_simple_pull_u8(adv_data);
if (len == 0) {
/* No data in this AD Structure. */
continue;
}

if (len > adv_data->len) {
/* Malformed AD Structure. */
break;
}

type = net_buf_simple_pull_u8(adv_data);
memcpy(data, net_buf_simple_pull_mem(adv_data, len), len);
if ((--len) > 0) {
uint8_t dlen;

/* Pull all length, but print only what fits into `data` array. */
dlen = MIN(len, sizeof(data) - 1);
memcpy(data, net_buf_simple_pull_mem(adv_data, len), dlen);
len = dlen;
}
data[len] = '\0';

if (type == BT_DATA_URI) {
Expand Down

0 comments on commit ddd2bc9

Please sign in to comment.