diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2019-08-29 15:09:29 +0200 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2019-08-29 15:09:40 +0200 |
commit | 59903772fae0f8ef76c7ecdb0eaef1a677df9a9e (patch) | |
tree | d4d00957f7fe4c1d1b248a77147fe86e7932ac65 | |
parent | df86074abe59543a8f4d245978d27d8ba1141089 (diff) |
trx_toolkit/data_msg.py: fix: make sure header version is known
Before using DATA_MSG.HDR_LEN, we need to make sure that a parsed
header version is known and supported. Otherwise we will get an
IndexError exception.
Change-Id: Ie1887aa8709da1a2a287aa58a7873e72c0b4ed33
-rw-r--r-- | src/target/trx_toolkit/data_msg.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/target/trx_toolkit/data_msg.py b/src/target/trx_toolkit/data_msg.py index c5d284df..a1c41c05 100644 --- a/src/target/trx_toolkit/data_msg.py +++ b/src/target/trx_toolkit/data_msg.py @@ -279,11 +279,13 @@ class DATAMSG: if len(msg) < self.CHDR_LEN: raise ValueError("Message is to short: missing common header") - # Parse version and TDMA TN + # Parse the header version first self.ver = (msg[0] >> 4) - self.tn = (msg[0] & 0x07) + if not self.ver in self.known_versions: + raise ValueError("Unknown TRXD header version %d" % self.ver) - # Parse TDMA FN + # Parse TDMA TN and FN + self.tn = (msg[0] & 0x07) self.fn = struct.unpack(">L", msg[1:5])[0] # Make sure we have the whole header, |