Skip to content

Commit 4e38f9e

Browse files
committed
check topic length against remaining length
1 parent 2d7491d commit 4e38f9e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,12 @@ def _wait_for_msg(self, timeout=0.1):
921921
# topic length MSB & LSB
922922
topic_len = self._sock_exact_recv(2)
923923
topic_len = (topic_len[0] << 8) | topic_len[1]
924+
925+
if topic_len > sz - 2:
926+
raise MMQTTException(
927+
f"Topic length {topic_len} in PUBLISH packet exceeds remaining length {sz} - 2"
928+
)
929+
924930
topic = self._sock_exact_recv(topic_len)
925931
topic = str(topic, "utf-8")
926932
sz -= topic_len + 2

0 commit comments

Comments
 (0)