diff options
author | Jeff Dowling <jeffd.aosp@gmail.com> | 2015-12-02 06:14:22 -0800 |
---|---|---|
committer | Jeff Dowling <jeffd.aosp@gmail.com> | 2015-12-02 10:44:56 -0800 |
commit | 26fca44fe0fac207e900bff88edf95c6be5cd107 (patch) | |
tree | 0c40297c192d8117f76b0bf9941dfb5a89cd0971 | |
parent | 3451232e591c8b9d7eda001e53ca960f396c1024 (diff) | |
download | chromium-libpac-26fca44fe0fac207e900bff88edf95c6be5cd107.tar.gz |
Fix for PAC script function dnsResolve.
Issue: DnsResolveImpl treats hostent’s h_addr_list[0] as a
null terminated ascii string. h_addr_list is type char** but the data
is null terminated network ordered bytes.
Fix: Convert h_addr_list[0] to a string via inet_ntop.
Note: This change only fixes IPv4 function.
A separate change will be submitted to fix IPv6 function
dnsResolveEx.
Be sure to clear browser cache between test attempts, as pages may be
loaded from cache. When loaded from cache, PAC processing is skipped.
The simplest PAC file to repoduce the issue:
function FindProxyForURL(url, host) {
alert(dnsResolve("localhost"));
return "DIRECT";
}
Change-Id: I78603d1ba953ae40ba8562fe638c197dfa9814cf
Signed-off-by: Jeff Dowling <jeffd.aosp@gmail.com>
-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; } |