Skip to content

Commit 75048f6

Browse files
authored
Merge pull request #56 from bstbud/bf_invalid_event_size
bail out when invalid event_size encountered
2 parents 938010d + 7a006e9 commit 75048f6

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/bosch/bhy2.c

+18-9
Original file line numberDiff line numberDiff line change
@@ -1494,18 +1494,27 @@ static int8_t parse_fifo(enum bhy2_fifo_type source, struct bhy2_fifo_buffer *fi
14941494
{
14951495
break;
14961496
}
1497-
if (info.callback != NULL)
1497+
1498+
if (info.event_size > 0)
14981499
{
1499-
/* Read position is incremented by 1 to exclude sensor id */
1500-
data_info.data_ptr = &fifo_p->buffer[tmp_read_pos + 1];
1501-
data_info.fifo_type = source;
1502-
data_info.time_stamp = time_stamp;
1503-
data_info.sensor_id = tmp_sensor_id;
1504-
data_info.data_size = info.event_size;
1505-
info.callback(&data_info, info.callback_ref);
1500+
if (info.callback != NULL)
1501+
{
1502+
/* Read position is incremented by 1 to exclude sensor id */
1503+
data_info.data_ptr = &fifo_p->buffer[tmp_read_pos + 1];
1504+
data_info.fifo_type = source;
1505+
data_info.time_stamp = time_stamp;
1506+
data_info.sensor_id = tmp_sensor_id;
1507+
data_info.data_size = info.event_size;
1508+
info.callback(&data_info, info.callback_ref);
1509+
}
15061510

1511+
fifo_p->read_pos += info.event_size;
1512+
}
1513+
else
1514+
{
1515+
//printf("error found parsing fifo, invalid frame found @:%d\n", fifo_p->read_pos);
1516+
return BHY2_E_INVALID_EVENT_SIZE;
15071517
}
1508-
fifo_p->read_pos += info.event_size;
15091518
break;
15101519
}
15111520
}

0 commit comments

Comments
 (0)