From 01db9e4a83b6d5e910e09f8bd696568904df31bb Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sat, 26 Aug 2023 06:35:34 -0700 Subject: [PATCH] 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 ba4c4f194aab30a8673f30983df42db7d9be7478. --- python/uds.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/uds.py b/python/uds.py index 9b25dffe6..f60720941 100644 --- a/python/uds.py +++ b/python/uds.py @@ -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:]