From c8eae279511319a0356f5f96cabb90e13d0dd6a1 Mon Sep 17 00:00:00 2001 From: M1nd3r Date: Mon, 14 Apr 2025 16:26:24 +0200 Subject: [PATCH] fix(python): discard messages from other channels --- python/src/trezorlib/transport/thp/protocol_v2.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/src/trezorlib/transport/thp/protocol_v2.py b/python/src/trezorlib/transport/thp/protocol_v2.py index 9d28fa158b..1218a1d6bb 100644 --- a/python/src/trezorlib/transport/thp/protocol_v2.py +++ b/python/src/trezorlib/transport/thp/protocol_v2.py @@ -281,11 +281,14 @@ class ProtocolV2Channel(Channel): def read_and_decrypt(self) -> t.Tuple[int, int, bytes]: header, raw_payload = self._read_until_valid_crc_check() + if header.cid != self.channel_id: + # TODO fix this recursion + # Received message from different channel - discard + return self.read_and_decrypt() if control_byte.is_ack(header.ctrl_byte): # TODO fix this recursion return self.read_and_decrypt() if control_byte.is_error(header.ctrl_byte): - # TODO check for different channel err = _get_error_from_int(raw_payload[0]) raise Exception("Received ThpError: " + err) if not header.is_encrypted_transport():