Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mqtt_sn_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,15 @@ int SN_Decode_Register(byte *rx_buf, int rx_buf_len, SN_Register *regist)
}
rx_payload += rc;

/* total_len must cover at least the bytes consumed so far
* (length + type + topicId + packet_id); otherwise the topic-name
* length computation below underflows and the NUL terminator is
* written before regist->topicName, leaving the field pointing at
* non-terminated memory past the parsed packet. */
if ((word32)total_len < (word32)(rx_payload - rx_buf)) {
return MQTT_TRACE_ERROR(MQTT_CODE_ERROR_MALFORMED_DATA);
}

/* Decode Topic Name */
regist->topicName = (char*)rx_payload;

Expand Down