mdns: fix crash for hostname queries

Receiving TXT, PTR, SDPTR and SRV record type queries would crash the application if the hostname
 was used as instance name.

Closes https://github.com/espressif/esp-idf/issues/4224
This commit is contained in:
Marius Vikhammer 2019-10-24 16:41:53 +08:00
parent 7aee8722fe
commit e94215443b

View file

@ -441,6 +441,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;
@ -485,6 +489,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";
@ -530,6 +538,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;
@ -598,6 +610,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;
@ -1147,6 +1163,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;