iso-tp: more sanity checks (#1487)

* assert rx not done for single frame to be valid

* not sure if this is correct yet

* return if updated

reverts some of https://github.com/commaai/panda/pull/1314

* Revert "return if updated"

This reverts commit ba4c4f194a.
This commit is contained in:
Shane Smiskol 2023-08-26 06:35:34 -07:00 committed by GitHub
parent f7a1daab74
commit 01db9e4a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -473,6 +473,7 @@ class IsoTpMessage():
# assert len(rx_data) == self.max_len, f"isotp - rx: invalid CAN frame length: {len(rx_data)}"
if rx_data[0] >> 4 == ISOTP_FRAME_TYPE.SINGLE:
assert not self.rx_done, "isotp - rx: unexpected single frame"
self.rx_len = rx_data[0] & 0x0F
assert self.rx_len < self.max_len, f"isotp - rx: invalid single frame length: {self.rx_len}"
self.rx_dat = rx_data[1:1 + self.rx_len]
@ -483,6 +484,7 @@ class IsoTpMessage():
return ISOTP_FRAME_TYPE.SINGLE
elif rx_data[0] >> 4 == ISOTP_FRAME_TYPE.FIRST:
assert self.rx_dat == b"", "isotp - rx: first frame with data already received"
self.rx_len = ((rx_data[0] & 0x0F) << 8) + rx_data[1]
assert self.max_len <= self.rx_len, f"isotp - rx: invalid first frame length: {self.rx_len}"
self.rx_dat = rx_data[2:]