Merge pull request #8649

2c24322 DNSResolver: fix not handling hostnames without dot characters [release] (Jeffrey Ryan)
This commit is contained in:
luigi1111 2023-01-11 11:41:56 -05:00
commit 153819fc4c
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
3 changed files with 11 additions and 24 deletions

View File

@ -327,11 +327,6 @@ std::vector<std::string> DNSResolver::get_record(const std::string& url, int rec
dnssec_available = false; dnssec_available = false;
dnssec_valid = false; dnssec_valid = false;
if (!check_address_syntax(url.c_str()))
{
return addresses;
}
// destructor takes care of cleanup // destructor takes care of cleanup
ub_result_ptr result; ub_result_ptr result;
@ -414,16 +409,6 @@ DNSResolver DNSResolver::create()
return DNSResolver(); return DNSResolver();
} }
bool DNSResolver::check_address_syntax(const char *addr) const
{
// if string doesn't contain a dot, we won't consider it a url for now.
if (strchr(addr,'.') == NULL)
{
return false;
}
return true;
}
namespace dns_utils namespace dns_utils
{ {

View File

@ -159,15 +159,6 @@ private:
// TODO: modify this to accommodate DNSSEC // TODO: modify this to accommodate DNSSEC
std::vector<std::string> get_record(const std::string& url, int record_type, boost::optional<std::string> (*reader)(const char *,size_t), bool& dnssec_available, bool& dnssec_valid); std::vector<std::string> get_record(const std::string& url, int record_type, boost::optional<std::string> (*reader)(const char *,size_t), bool& dnssec_available, bool& dnssec_valid);
/**
* @brief Checks a string to see if it looks like a URL
*
* @param addr the string to be checked
*
* @return true if it looks enough like a URL, false if not
*/
bool check_address_syntax(const char *addr) const;
DNSResolverData *m_data; DNSResolverData *m_data;
}; // class DNSResolver }; // class DNSResolver

View File

@ -158,6 +158,17 @@ TEST(DNSResolver, GetTXTRecord)
EXPECT_STREQ("donate.getmonero.org", addr.c_str()); EXPECT_STREQ("donate.getmonero.org", addr.c_str());
} }
TEST(DNSResolver, Localhost)
{
tools::DNSResolver resolver = tools::DNSResolver::create();
bool avail, valid;
std::vector<std::string> ips = resolver.get_ipv4("localhost", avail, valid);
ASSERT_EQ(1, ips.size());
ASSERT_EQ("127.0.0.1", ips[0]);
}
bool is_equal(const char *s, const std::vector<std::string> &v) { return v.size() == 1 && v[0] == s; } bool is_equal(const char *s, const std::vector<std::string> &v) { return v.size() == 1 && v[0] == s; }
TEST(DNS_PUBLIC, empty) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("").empty()); } TEST(DNS_PUBLIC, empty) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("").empty()); }