Skip to content

Commit

Permalink
Util: more checks in get_dns_txt_records_base
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Nov 7, 2023
1 parent 8699e18 commit f4d709c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,22 +508,29 @@ bool get_dns_txt_records_base(const std::string& host, Callback<void, const char
}

#ifdef _WIN32
PDNS_RECORD pQueryResults;
if (DnsQuery(host.c_str(), DNS_TYPE_TEXT, DNS_QUERY_STANDARD, NULL, &pQueryResults, NULL) != 0) {
return false;
}
try {
PDNS_RECORD pQueryResults;
if (DnsQuery(host.c_str(), DNS_TYPE_TEXT, DNS_QUERY_STANDARD, NULL, &pQueryResults, NULL) != 0) {
return false;
}

for (PDNS_RECORD p = pQueryResults; p; p = p->pNext) {
for (size_t j = 0; j < p->Data.TXT.dwStringCount; ++j) {
const char* s = p->Data.TXT.pStringArray[j];
const size_t n = strlen(s);
if (n > 0) {
callback(s, n);
for (PDNS_RECORD p = pQueryResults; p; p = p->pNext) {
for (size_t j = 0; j < p->Data.TXT.dwStringCount; ++j) {
const char* s = p->Data.TXT.pStringArray[j];
if (s) {
const size_t n = strlen(s);
if (n > 0) {
callback(s, n);
}
}
}
}
}

DnsRecordListFree(pQueryResults, DnsFreeRecordList);
DnsRecordListFree(pQueryResults, DnsFreeRecordList);
}
catch (...) {
return false;
}

return true;
#elif defined(HAVE_RES_QUERY)
Expand Down

0 comments on commit f4d709c

Please sign in to comment.