diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2016-02-01 02:39:30 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-01 02:39:30 +0000 |
commit | 94b900307eef6c62378c68e1b2b4c7578283bc59 (patch) | |
tree | 0c40297c192d8117f76b0bf9941dfb5a89cd0971 | |
parent | 3451232e591c8b9d7eda001e53ca960f396c1024 (diff) | |
parent | 26fca44fe0fac207e900bff88edf95c6be5cd107 (diff) | |
download | chromium-libpac-94b900307eef6c62378c68e1b2b4c7578283bc59.tar.gz |
Merge "Fix for PAC script function dnsResolve."
-rw-r--r-- | src/proxy_resolver_js_bindings.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/proxy_resolver_js_bindings.cc b/src/proxy_resolver_js_bindings.cc index 897fde4..0686f23 100644 --- a/src/proxy_resolver_js_bindings.cc +++ b/src/proxy_resolver_js_bindings.cc @@ -5,6 +5,7 @@ #include "proxy_resolver_js_bindings.h" #include "proxy_resolver_v8.h" +#include <arpa/inet.h> #include <netdb.h> #include <unistd.h> #include <cstddef> @@ -64,10 +65,16 @@ class DefaultJSBindings : public ProxyResolverJSBindings { std::string* first_ip_address) { struct hostent* he = gethostbyname(host.c_str()); - if (he == NULL) { + if (he == NULL || he->h_addr == NULL || he->h_addrtype != AF_INET) { return false; } - *first_ip_address = std::string(he->h_addr); + + char tmp[INET_ADDRSTRLEN]; + if (inet_ntop(he->h_addrtype, he->h_addr, tmp, sizeof(tmp)) == NULL) { + return false; + } + + *first_ip_address = std::string(tmp); return true; } |