Skip to content

Commit

Permalink
[nrf toup] packet: Fix heap corruption
Browse files Browse the repository at this point in the history
While parsing the packet all TLV's are NULl terminated explicitly, so,
take in to account the NULL terminating byte while memory allocation.

Else, this overrides other memory causing hard to debug heap
corruptions.

Fixes SHEL-2754.

Signed-off-by: Chaitanya Tata <[email protected]>
  • Loading branch information
krish2718 committed May 28, 2024
1 parent 9f75760 commit 28cb907
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion indigo_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int parse_tlv(struct tlv_hdr *tlv, char *packet, size_t packet_len) {

tlv->id = ((packet[0] & 0x00ff) << 8) | (packet[1] & 0x00ff);
tlv->len = packet[2];
tlv->value = (char*)malloc(sizeof(char) * tlv->len);
tlv->value = (char*)malloc((sizeof(char) * tlv->len) + 1);
if (!tlv->value) {
indigo_logger(LOG_LEVEL_ERROR, "Failed to allocate memory for TLV value: %d", tlv->len);
return -1;
Expand Down

0 comments on commit 28cb907

Please sign in to comment.