Skip to content

Commit 9fdbe5f

Browse files
mdns: Fix alloc issue if TXT has empty value
* Original commit: espressif/esp-idf@205f6ba
1 parent 20e6e9e commit 9fdbe5f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

components/mdns/mdns.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ static uint16_t _mdns_append_txt_record(uint8_t * packet, uint16_t * index, mdns
778778
char * tmp;
779779
mdns_txt_linked_item_t * txt = service->txt;
780780
while (txt) {
781-
uint8_t txt_data_len = strlen(txt->key) + txt->value_len + 1;
782-
tmp = (char *)malloc(txt_data_len);
781+
uint8_t txt_data_len = strlen(txt->key) + txt->value_len + 1 /* + '=' char */;
782+
tmp = (char *)malloc(txt_data_len + 1 /* + '\0' term-char in sprintf() */);
783783
if (tmp) {
784784
int offset = sprintf(tmp, "%s=", txt->key);
785785
memcpy(tmp + offset, txt->value, txt->value_len);

0 commit comments

Comments
 (0)