From 51dde19a765533af67fc7be21f116641773a9be4 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 17 Jan 2018 19:06:42 +0200 Subject: [PATCH] mdns: Fix issue with some mDNS parsers Some mDNS parser have issue with zero terminated TXT lists. This fix targets to overcome this issue. Found and tested with jmdns. --- components/mdns/mdns.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 061c631483..bc8a94e3fa 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -803,7 +803,7 @@ static uint16_t _mdns_append_txt_record(uint8_t * packet, uint16_t * index, mdns record_length += part_length; uint16_t data_len_location = *index - 2; - uint16_t data_len = 1; + uint16_t data_len = 0; char * tmp; mdns_txt_linked_item_t * txt = service->txt; @@ -820,9 +820,11 @@ static uint16_t _mdns_append_txt_record(uint8_t * packet, uint16_t * index, mdns } txt = txt->next; } - - packet[*index] = 0; - *index = *index + 1; + if (!data_len) { + data_len = 1; + packet[*index] = 0; + *index = *index + 1; + } _mdns_set_u16(packet, data_len_location, data_len); record_length += data_len; return record_length;