fix parsing unexpected mdns txt response
This commit is contained in:
@@ -579,23 +579,33 @@ int resolveMdnsOneShot(const char* url, mdns_oneshot_t *result, mdns_oneshot_t *
|
|||||||
printf(" %s=%s\n", (atype == DNS_TYPE_TXT) ? "txt" : "ptr", name);
|
printf(" %s=%s\n", (atype == DNS_TYPE_TXT) ? "txt" : "ptr", name);
|
||||||
#endif
|
#endif
|
||||||
if (atype == DNS_TYPE_TXT && name[0]) {
|
if (atype == DNS_TYPE_TXT && name[0]) {
|
||||||
|
// parse id=xxxxxxxxxxxx[.proto=xxx]
|
||||||
char* sep = strchr(name, '=');
|
char* sep = strchr(name, '=');
|
||||||
char* sep2;
|
char* sep2;
|
||||||
if (sep && strncmp(name, "id", sep-name) == 0) {
|
if (sep && sep-name == 2 && strncmp(name, "id", 2) == 0) {
|
||||||
sep2 = strchr(name, '.');
|
sep2 = strchr(sep+1, '.');
|
||||||
|
if (!sep2) {
|
||||||
|
sep2 = name + pos;
|
||||||
|
}
|
||||||
if (sep2-sep-1 == sizeof(mdns_oneshot_t::id)-1) {
|
if (sep2-sep-1 == sizeof(mdns_oneshot_t::id)-1) {
|
||||||
memcpy(id, sep+1, sizeof(mdns_oneshot_t::id)-1);
|
memcpy(id, sep+1, sizeof(mdns_oneshot_t::id)-1);
|
||||||
} else {
|
} else {
|
||||||
sep = nullptr;
|
sep = nullptr;
|
||||||
}
|
}
|
||||||
sep = sep ? strchr(sep2+1, '=') : nullptr;
|
sep = sep && sep2 < name + pos ? strchr(sep2+1, '=') : nullptr;
|
||||||
|
} else {
|
||||||
|
sep2 = name - 1;
|
||||||
}
|
}
|
||||||
if (sep && strncmp(sep2+1, "proto", sep-sep2-1) == 0 && (
|
if (sep && sep-sep2-1 == 5 && strncmp(sep2+1, "proto", 5) == 0) {
|
||||||
pos == (size_t)(sep-name)+1+sizeof(mdns_oneshot_t::proto)-1
|
sep2 = strchr(sep+1, '.');
|
||||||
|| strchr(sep+1, '.') == sep+1+sizeof(mdns_oneshot_t::proto)-1)) {
|
if (!sep2) {
|
||||||
|
sep2 = name + pos;
|
||||||
|
}
|
||||||
|
if (sep2-sep-1 == sizeof(mdns_oneshot_t::proto)-1) {
|
||||||
memcpy(proto, sep+1, sizeof(mdns_oneshot_t::proto)-1);
|
memcpy(proto, sep+1, sizeof(mdns_oneshot_t::proto)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (atype == DNS_TYPE_SRV && rdLen >= sizeof(dns_rr_srv_t)) {
|
} else if (atype == DNS_TYPE_SRV && rdLen >= sizeof(dns_rr_srv_t)) {
|
||||||
dns_rr_srv_t *srv = reinterpret_cast<dns_rr_srv_t*>(record+len);
|
dns_rr_srv_t *srv = reinterpret_cast<dns_rr_srv_t*>(record+len);
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user