mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-16 07:10:34 +08:00
dronecan: SocketCAN driver check size before copying
Avoids memory corruption if we get packets to big
This commit is contained in:
committed by
David Sidrane
parent
470bea9ba8
commit
ebfa53286f
@@ -218,12 +218,22 @@ uavcan::int16_t CanIface::receive(uavcan::CanFrame &out_frame, uavcan::Monotonic
|
||||
if (_can_fd) {
|
||||
struct canfd_frame *recv_frame = (struct canfd_frame *)&_recv_frame;
|
||||
out_frame.id = recv_frame->can_id;
|
||||
|
||||
if (recv_frame->len > CANFD_MAX_DLEN) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
out_frame.dlc = recv_frame->len;
|
||||
memcpy(out_frame.data, &recv_frame->data, recv_frame->len);
|
||||
|
||||
} else {
|
||||
struct can_frame *recv_frame = (struct can_frame *)&_recv_frame;
|
||||
out_frame.id = recv_frame->can_id;
|
||||
|
||||
if (recv_frame->can_dlc > CAN_MAX_DLEN) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
out_frame.dlc = recv_frame->can_dlc;
|
||||
memcpy(out_frame.data, &recv_frame->data, recv_frame->can_dlc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user