diff options
author | Riccardo Spagni <ric@spagni.net> | 2014-09-25 02:17:49 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-09-25 02:17:58 +0200 |
commit | 5cd77a9f0b041779d54e2531f98038020c33f4da (patch) | |
tree | 9fae45e3eea0797034b81d9501f246145f0d1b56 | |
parent | Added ability to read chechpoint hashes from json file in data folder (diff) | |
parent | libunbound has const correctness issues... (diff) | |
download | monero-5cd77a9f0b041779d54e2531f98038020c33f4da.tar.xz |
Merge pull request #159
7383574 libunbound has const correctness issues... (Thomas Winget)
-rw-r--r-- | src/common/dns_utils.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index ab41ea60e..e1151e190 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "common/dns_utils.h" +#include <cstring> #include <sstream> #include <ldns/rr.h> // for RR type and class defs #include <unbound.h> @@ -99,9 +100,11 @@ DNSResolver::DNSResolver() : m_data(new DNSResolverData()) // init libunbound context m_data->m_ub_context = ub_ctx_create(); + char empty_string = '\0'; + // look for "/etc/resolv.conf" and "/etc/hosts" or platform equivalent - ub_ctx_resolvconf(m_data->m_ub_context, ""); - ub_ctx_hosts(m_data->m_ub_context, ""); + ub_ctx_resolvconf(m_data->m_ub_context, &empty_string); + ub_ctx_hosts(m_data->m_ub_context, &empty_string); } DNSResolver::~DNSResolver() @@ -119,7 +122,10 @@ DNSResolver::~DNSResolver() std::vector<std::string> DNSResolver::get_ipv4(const std::string& url) { std::vector<std::string> addresses; + char urlC[1000]; // waaaay too big, but just in case... + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; if (!check_address_syntax(url)) { return addresses; @@ -129,7 +135,7 @@ std::vector<std::string> DNSResolver::get_ipv4(const std::string& url) ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { @@ -146,6 +152,10 @@ std::vector<std::string> DNSResolver::get_ipv4(const std::string& url) std::vector<std::string> DNSResolver::get_ipv6(const std::string& url) { std::vector<std::string> addresses; + char urlC[1000]; // waaaay too big, but just in case... + + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; if (!check_address_syntax(url)) { @@ -155,7 +165,7 @@ std::vector<std::string> DNSResolver::get_ipv6(const std::string& url) ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { @@ -172,6 +182,10 @@ std::vector<std::string> DNSResolver::get_ipv6(const std::string& url) std::vector<std::string> DNSResolver::get_txt_record(const std::string& url) { std::vector<std::string> records; + char urlC[1000]; // waaaay too big, but just in case... + + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; if (!check_address_syntax(url)) { @@ -181,7 +195,7 @@ std::vector<std::string> DNSResolver::get_txt_record(const std::string& url) ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { |