summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2019-08-29 14:53:47 +0200
committerVadim Yanitskiy <axilirator@gmail.com>2019-08-29 15:04:28 +0200
commitdf86074abe59543a8f4d245978d27d8ba1141089 (patch)
tree41cc073a988b82911eb6a1de0b871bf7ea558385
parent5fed799df38a1c9327b809a22f65b9b5c55022fe (diff)
trx_toolkit/data_msg.py: fix message length check in parse_msg()
Unlike DATA_MSG.HDR_LEN, the CHDR_LEN is a constant that defines length of the common header, which is mandatory for every version. DATA_MSG.HDR_LEN in its turn defines length of the whole header, including the version specific fields. Thus we need to know the header version before using it. In DATA_MSG.parse_msg() we need to parse the common header first, so then we know the version and length of the whole header. After that we can safely use DATA_MSG.HDR_LEN. Change-Id: I2809f5f96209eed64bdabf7a15575144313f7cc9
-rw-r--r--src/target/trx_toolkit/data_msg.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/target/trx_toolkit/data_msg.py b/src/target/trx_toolkit/data_msg.py
index a1046ec9..c5d284df 100644
--- a/src/target/trx_toolkit/data_msg.py
+++ b/src/target/trx_toolkit/data_msg.py
@@ -275,9 +275,9 @@ class DATAMSG:
# Parses a TRX DATA message
def parse_msg(self, msg):
- # Make sure we have at least header
- if len(msg) < self.HDR_LEN:
- raise ValueError("Message is to short")
+ # Make sure we have at least common header
+ if len(msg) < self.CHDR_LEN:
+ raise ValueError("Message is to short: missing common header")
# Parse version and TDMA TN
self.ver = (msg[0] >> 4)
@@ -286,6 +286,11 @@ class DATAMSG:
# Parse TDMA FN
self.fn = struct.unpack(">L", msg[1:5])[0]
+ # Make sure we have the whole header,
+ # including the version specific fields
+ if len(msg) < self.HDR_LEN:
+ raise ValueError("Message is to short: missing version specific header")
+
# Specific message part
self.parse_hdr(msg)