diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 22:10:11 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-31 22:10:11 +0000 |
commit | a5e9f2cddd474bf0ea266e998251431493471325 (patch) | |
tree | ce0a42af022ae058372065a2887962a9eca73474 | |
parent | f31b7a05f88fbddd14428827b351fe736133e26e (diff) | |
download | chromium_src-a5e9f2cddd474bf0ea266e998251431493471325.zip chromium_src-a5e9f2cddd474bf0ea266e998251431493471325.tar.gz chromium_src-a5e9f2cddd474bf0ea266e998251431493471325.tar.bz2 |
Fix a crash when calling a PAC binding from the global scope.
BUG=40026
TEST=ProxyResolverV8Test.BindingCalledDuringInitialization
Review URL: http://codereview.chromium.org/1520009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43268 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/data/proxy_resolver_v8_unittest/binding_from_global.js | 8 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_v8.cc | 26 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_v8_unittest.cc | 28 |
3 files changed, 48 insertions, 14 deletions
diff --git a/net/data/proxy_resolver_v8_unittest/binding_from_global.js b/net/data/proxy_resolver_v8_unittest/binding_from_global.js new file mode 100644 index 0000000..91bbcf2 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/binding_from_global.js @@ -0,0 +1,8 @@ +// Calls a bindings outside of FindProxyForURL(). This causes the code to +// get exercised during initialization. + +var x = myIpAddress(); + +function FindProxyForURL(url, host) { + return "PROXY " + x + ":80"; +} diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc index 7687fe7..8734dff 100644 --- a/net/proxy/proxy_resolver_v8.cc +++ b/net/proxy/proxy_resolver_v8.cc @@ -214,7 +214,7 @@ class ProxyResolverV8::Context { return OK; } - void SetCurrentRequestNetLog(BoundNetLog* net_log) { + void SetCurrentRequestNetLog(const BoundNetLog& net_log) { current_request_net_log_ = net_log; } @@ -293,14 +293,14 @@ class ProxyResolverV8::Context { Context* context = static_cast<Context*>(v8::External::Cast(*args.Data())->Value()); - context->current_request_net_log_->BeginEvent( + context->current_request_net_log_.BeginEvent( NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS); // We shouldn't be called with any arguments, but will not complain if // we are. std::string result = context->js_bindings_->MyIpAddress(); - context->current_request_net_log_->EndEvent( + context->current_request_net_log_.EndEvent( NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS); if (result.empty()) @@ -314,14 +314,14 @@ class ProxyResolverV8::Context { Context* context = static_cast<Context*>(v8::External::Cast(*args.Data())->Value()); - context->current_request_net_log_->BeginEvent( + context->current_request_net_log_.BeginEvent( NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS_EX); // We shouldn't be called with any arguments, but will not complain if // we are. std::string result = context->js_bindings_->MyIpAddressEx(); - context->current_request_net_log_->EndEvent( + context->current_request_net_log_.EndEvent( NetLog::TYPE_PROXY_RESOLVER_V8_MY_IP_ADDRESS_EX); return StdStringToV8String(result); @@ -341,12 +341,12 @@ class ProxyResolverV8::Context { return v8::Undefined(); } - context->current_request_net_log_->BeginEvent( + context->current_request_net_log_.BeginEvent( NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE); std::string result = context->js_bindings_->DnsResolve(host); - context->current_request_net_log_->EndEvent( + context->current_request_net_log_.EndEvent( NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE); // DnsResolve() returns empty string on failure. @@ -367,19 +367,19 @@ class ProxyResolverV8::Context { return v8::Undefined(); } - context->current_request_net_log_->BeginEvent( + context->current_request_net_log_.BeginEvent( NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE_EX); std::string result = context->js_bindings_->DnsResolveEx(host); - context->current_request_net_log_->EndEvent( + context->current_request_net_log_.EndEvent( NetLog::TYPE_PROXY_RESOLVER_V8_DNS_RESOLVE_EX); return StdStringToV8String(result); } ProxyResolverJSBindings* js_bindings_; - BoundNetLog* current_request_net_log_; + BoundNetLog current_request_net_log_; v8::Persistent<v8::External> v8_this_; v8::Persistent<v8::Context> v8_context_; }; @@ -404,12 +404,10 @@ int ProxyResolverV8::GetProxyForURL(const GURL& query_url, if (!context_.get()) return ERR_FAILED; - BoundNetLog log(net_log); - // Otherwise call into V8. - context_->SetCurrentRequestNetLog(&log); + context_->SetCurrentRequestNetLog(net_log); int rv = context_->ResolveProxy(query_url, results); - context_->SetCurrentRequestNetLog(NULL); + context_->SetCurrentRequestNetLog(BoundNetLog()); return rv; } diff --git a/net/proxy/proxy_resolver_v8_unittest.cc b/net/proxy/proxy_resolver_v8_unittest.cc index 904bf7c..b124c66 100644 --- a/net/proxy/proxy_resolver_v8_unittest.cc +++ b/net/proxy/proxy_resolver_v8_unittest.cc @@ -416,6 +416,34 @@ TEST(ProxyResolverV8Test, V8Bindings) { EXPECT_EQ("foobar", bindings->dns_resolves_ex[1]); } +// Test calling a binding (myIpAddress()) from the script's global scope. +// http://crbug.com/40026 +TEST(ProxyResolverV8Test, BindingCalledDuringInitialization) { + ProxyResolverV8WithMockBindings resolver; + + int result = resolver.SetPacScriptFromDisk("binding_from_global.js"); + EXPECT_EQ(OK, result); + + MockJSBindings* bindings = resolver.mock_js_bindings(); + + // myIpAddress() got called during initialization of the script. + EXPECT_EQ(1, bindings->my_ip_address_count); + + ProxyInfo proxy_info; + result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, NULL); + + EXPECT_EQ(OK, result); + EXPECT_FALSE(proxy_info.is_direct()); + EXPECT_EQ("127.0.0.1:80", proxy_info.proxy_server().ToURI()); + + // Check that no other bindings were called. + EXPECT_EQ(0U, bindings->errors.size()); + ASSERT_EQ(0U, bindings->alerts.size()); + ASSERT_EQ(0U, bindings->dns_resolves.size()); + EXPECT_EQ(0, bindings->my_ip_address_ex_count); + ASSERT_EQ(0U, bindings->dns_resolves_ex.size()); +} + // Test that calls to the myIpAddress() and dnsResolve() bindings get // logged to the NetLog parameter. TEST(ProxyResolverV8Test, NetLog) { |