Skip to content

Commit

Permalink
allow only valid fd message lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
cymotive-eldad-sitbon committed Sep 5, 2024
1 parent e750caa commit 2cea27d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion can/interfaces/socketcan/socketcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def build_can_frame(msg: Message) -> bytes:

data = bytes(msg.data).ljust(max_len, b"\x00")

return CAN_FRAME_HEADER_STRUCT.pack(can_id, len(msg.data), flags, msg.dlc) + data
data_len = min(i for i in can.util.CAN_FD_DLC if i >= len(msg.data))
return CAN_FRAME_HEADER_STRUCT.pack(can_id, data_len, flags, msg.dlc) + data


def build_bcm_header(
Expand Down Expand Up @@ -321,6 +322,9 @@ def dissect_can_frame(frame: bytes) -> Tuple[int, int, int, bytes]:
# Flags not valid in non-FD frames
flags = 0

if data_len not in can.util.CAN_FD_DLC:
data_len = min(i for i in can.util.CAN_FD_DLC if i >= data_len)

# Allow deprecated can frames with old struct
if (
data_len == constants.CAN_MAX_DLEN and
Expand Down

0 comments on commit 2cea27d

Please sign in to comment.