Skip to content

Commit

Permalink
mdns: fix crash for hostname queries
Browse files Browse the repository at this point in the history
Receiving TXT, PTR, SDPTR and SRV record type queries would crash the application if the hostname
 was used as instance name.

Closes espressif/esp-idf#4224


* Original commit: espressif/esp-idf@3d11700
  • Loading branch information
ESP-Marius authored and suren-gabrielyan-espressif committed May 27, 2022
1 parent c28ce33 commit a098421
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ static uint16_t _mdns_append_ptr_record(uint8_t * packet, uint16_t * index, cons
uint16_t record_length = 0;
uint8_t part_length;

if (service == NULL) {
return 0;
}

str[0] = instance;
str[1] = service;
str[2] = proto;
Expand Down Expand Up @@ -489,6 +493,10 @@ static uint16_t _mdns_append_sdptr_record(uint8_t * packet, uint16_t * index, md
uint16_t record_length = 0;
uint8_t part_length;

if (service == NULL) {
return 0;
}

sd_str[0] = (char*)"_services";
sd_str[1] = (char*)"_dns-sd";
sd_str[2] = (char*)"_udp";
Expand Down Expand Up @@ -534,6 +542,10 @@ static uint16_t _mdns_append_txt_record(uint8_t * packet, uint16_t * index, mdns
uint16_t record_length = 0;
uint8_t part_length;

if (service == NULL) {
return 0;
}

str[0] = _mdns_get_service_instance_name(service);
str[1] = service->service;
str[2] = service->proto;
Expand Down Expand Up @@ -602,6 +614,10 @@ static uint16_t _mdns_append_srv_record(uint8_t * packet, uint16_t * index, mdns
uint16_t record_length = 0;
uint8_t part_length;

if (service == NULL) {
return 0;
}

str[0] = _mdns_get_service_instance_name(service);
str[1] = service->service;
str[2] = service->proto;
Expand Down Expand Up @@ -1151,6 +1167,7 @@ static bool _mdns_alloc_answer(mdns_out_answer_t ** destnation, uint16_t type, m
}
a->type = type;
a->service = service;
a->custom_service = NULL;
a->bye = bye;
a->flush = flush;
a->next = NULL;
Expand Down

0 comments on commit a098421

Please sign in to comment.