From f489232cdb89f804a86b723460ccba3e9e463dff Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 25 Oct 2020 18:50:32 +0000 Subject: [PATCH] Fix for crash reported by Michael Danilov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case uDNS returns a NULL txt pointer, don’t try to create a std::string from it, since this will crash, See: https://sourceforge.net/p/flightgear/codetickets/2398/ --- simgear/io/DNSClient.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/simgear/io/DNSClient.cxx b/simgear/io/DNSClient.cxx index 080d84ec..32a0c401 100644 --- a/simgear/io/DNSClient.cxx +++ b/simgear/io/DNSClient.cxx @@ -156,8 +156,13 @@ static void dnscbTXT(struct dns_ctx *ctx, struct dns_rr_txt *result, void *data) r->ttl = result->dnstxt_ttl; for (int i = 0; i < result->dnstxt_nrr; i++) { //TODO: interprete the .len field of dnstxt_txt? - string txt = string((char*)result->dnstxt_txt[i].txt); - r->entries.push_back( txt ); + auto rawTxt = reinterpret_cast(result->dnstxt_txt[i].txt); + if (!rawTxt) { + continue; + } + + const string txt{rawTxt}; + r->entries.push_back(txt); string_list tokens = simgear::strutils::split( txt, "=", 1 ); if( tokens.size() == 2 ) { r->attributes[tokens[0]] = tokens[1];