mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
mdns: fix ignoring mdns packet with some invalid name entries in question field
In case of invalid name entry, only this entry is invalidated and parsing continues as other query entries could contain questions to be responded to
This commit is contained in:
parent
7ec9f9ee74
commit
4bd4c7caf3
@ -174,7 +174,7 @@ static const uint8_t * _mdns_read_fqdn(const uint8_t * packet, const uint8_t * s
|
|||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
while (start[index]) {
|
while (start[index]) {
|
||||||
if (name->parts == 4) {
|
if (name->parts == 4) {
|
||||||
return NULL;
|
name->invalid = true;
|
||||||
}
|
}
|
||||||
uint8_t len = start[index++];
|
uint8_t len = start[index++];
|
||||||
if (len < 0xC0) {
|
if (len < 0xC0) {
|
||||||
@ -195,7 +195,7 @@ static const uint8_t * _mdns_read_fqdn(const uint8_t * packet, const uint8_t * s
|
|||||||
strlcat(name->host, buf, sizeof(name->host));
|
strlcat(name->host, buf, sizeof(name->host));
|
||||||
} else if (strcasecmp(buf, MDNS_SUB_STR) == 0) {
|
} else if (strcasecmp(buf, MDNS_SUB_STR) == 0) {
|
||||||
name->sub = 1;
|
name->sub = 1;
|
||||||
} else {
|
} else if (!name->invalid) {
|
||||||
char* mdns_name_ptrs[]={name->host, name->service, name->proto, name->domain};
|
char* mdns_name_ptrs[]={name->host, name->service, name->proto, name->domain};
|
||||||
memcpy(mdns_name_ptrs[name->parts++], buf, len+1);
|
memcpy(mdns_name_ptrs[name->parts++], buf, len+1);
|
||||||
}
|
}
|
||||||
@ -2315,6 +2315,7 @@ static const uint8_t * _mdns_parse_fqdn(const uint8_t * packet, const uint8_t *
|
|||||||
name->service[0] = 0;
|
name->service[0] = 0;
|
||||||
name->proto[0] = 0;
|
name->proto[0] = 0;
|
||||||
name->domain[0] = 0;
|
name->domain[0] = 0;
|
||||||
|
name->invalid = false;
|
||||||
|
|
||||||
static char buf[MDNS_NAME_BUF_LEN];
|
static char buf[MDNS_NAME_BUF_LEN];
|
||||||
|
|
||||||
@ -2322,7 +2323,7 @@ static const uint8_t * _mdns_parse_fqdn(const uint8_t * packet, const uint8_t *
|
|||||||
if (!next_data) {
|
if (!next_data) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!name->parts) {
|
if (!name->parts || name->invalid) {
|
||||||
return next_data;
|
return next_data;
|
||||||
}
|
}
|
||||||
if (name->parts == 3) {
|
if (name->parts == 3) {
|
||||||
@ -2620,7 +2621,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
|||||||
clas &= 0x7FFF;
|
clas &= 0x7FFF;
|
||||||
content = content + 4;
|
content = content + 4;
|
||||||
|
|
||||||
if (clas != 0x0001) {//bad class
|
if (clas != 0x0001 || name->invalid) {//bad class or invalid name for this question entry
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ typedef struct {
|
|||||||
char domain[MDNS_NAME_BUF_LEN];
|
char domain[MDNS_NAME_BUF_LEN];
|
||||||
uint8_t parts;
|
uint8_t parts;
|
||||||
uint8_t sub;
|
uint8_t sub;
|
||||||
|
bool invalid;
|
||||||
} mdns_name_t;
|
} mdns_name_t;
|
||||||
|
|
||||||
typedef struct mdns_parsed_question_s {
|
typedef struct mdns_parsed_question_s {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user