aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Dowling <jeffd.aosp@gmail.com>2015-12-02 06:14:22 -0800
committerBen Murdoch <benm@google.com>2017-01-12 17:00:15 +0000
commite45a964f8b6c24b0561fb438d68c03c014dd3008 (patch)
tree0c40297c192d8117f76b0bf9941dfb5a89cd0971
parenta75708abc689bcc1dd7573c18c23fe53af87a6aa (diff)
downloadchromium-libpac-e45a964f8b6c24b0561fb438d68c03c014dd3008.tar.gz
Fix for PAC script function dnsResolve. DO NOT MERGE.
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> (cherry picked from commit 26fca44fe0fac207e900bff88edf95c6be5cd107) Bug: 31987131 Bug: 29178923
-rw-r--r--src/proxy_resolver_js_bindings.cc11
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;
}