Change in ...osmocom-bb[master]: trx_toolkit/data_msg.py: fix message length check in parse_msg()

fixeria gerrit-no-reply at lists.osmocom.org
Thu Aug 29 13:27:07 UTC 2019


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/15331


Change subject: trx_toolkit/data_msg.py: fix message length check in parse_msg()
......................................................................

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
---
M src/target/trx_toolkit/data_msg.py
1 file changed, 8 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/31/15331/1

diff --git a/src/target/trx_toolkit/data_msg.py b/src/target/trx_toolkit/data_msg.py
index a1046ec..c5d284d 100644
--- a/src/target/trx_toolkit/data_msg.py
+++ b/src/target/trx_toolkit/data_msg.py
@@ -275,9 +275,9 @@
 
 	# 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 @@
 		# 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)
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/15331
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I2809f5f96209eed64bdabf7a15575144313f7cc9
Gerrit-Change-Number: 15331
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190829/8229f7c6/attachment.html>


More information about the gerrit-log mailing list