From b3f913a0580724dbca336e029d65607ba1ae0754 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 21 Jan 2022 14:18:22 +0100 Subject: [PATCH] mdns: Fix alloc issue if TXT has empty value --- components/mdns/mdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 8e8a86436e..2d37fc5997 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -702,8 +702,8 @@ static uint16_t _mdns_append_txt_record(uint8_t * packet, uint16_t * index, mdns char * tmp; mdns_txt_linked_item_t * txt = service->txt; while (txt) { - uint8_t txt_data_len = strlen(txt->key) + txt->value_len + 1; - tmp = (char *)malloc(txt_data_len); + uint8_t txt_data_len = strlen(txt->key) + txt->value_len + 1 /* + '=' char */; + tmp = (char *)malloc(txt_data_len + 1 /* + '\0' term-char in sprintf() */); if (tmp) { int offset = sprintf(tmp, "%s=", txt->key); memcpy(tmp + offset, txt->value, txt->value_len);