瀏覽代碼

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.
me-no-dev 8 年之前
父節點
當前提交
51dde19a76
共有 1 個文件被更改,包括 6 次插入4 次删除
  1. 6 4
      components/mdns/mdns.c

+ 6 - 4
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;