Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Unified Diff: net/proxy/proxy_resolver_v8.cc

Issue 950433002: Fix a crash when processing an invalid PAC script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add copyright to test data (placate presubmit) Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/proxy/proxy_resolver_v8.cc
diff --git a/net/proxy/proxy_resolver_v8.cc b/net/proxy/proxy_resolver_v8.cc
index 2bb858c46ead631ed73d9cdedd77756b9501f0f5..57d68b5d8f9af105ff66644307665e74b9dffe31 100644
--- a/net/proxy/proxy_resolver_v8.cc
+++ b/net/proxy/proxy_resolver_v8.cc
@@ -431,11 +431,9 @@ class ProxyResolverV8::Context {
v8::Context::Scope function_scope(context);
v8::Local<v8::Value> function;
- if (!GetFindProxyForURL(&function)) {
- js_bindings()->OnError(
- -1, base::ASCIIToUTF16("FindProxyForURL() is undefined."));
- return ERR_PAC_SCRIPT_FAILED;
- }
+ int rv = GetFindProxyForURL(&function);
+ if (rv != OK)
+ return rv;
v8::Local<v8::Value> argv[] = {
ASCIIStringToV8String(isolate_, query_url.spec()),
@@ -561,23 +559,41 @@ class ProxyResolverV8::Context {
// At a minimum, the FindProxyForURL() function must be defined for this
// to be a legitimiate PAC script.
v8::Local<v8::Value> function;
- if (!GetFindProxyForURL(&function)) {
- js_bindings()->OnError(
- -1, base::ASCIIToUTF16("FindProxyForURL() is undefined."));
- return ERR_PAC_SCRIPT_FAILED;
- }
-
- return OK;
+ return GetFindProxyForURL(&function);
}
private:
- bool GetFindProxyForURL(v8::Local<v8::Value>* function) {
+ int GetFindProxyForURL(v8::Local<v8::Value>* function) {
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(isolate_, v8_context_);
+
+ v8::TryCatch try_catch;
+
*function =
context->Global()->Get(
ASCIILiteralToV8String(isolate_, "FindProxyForURL"));
- return (*function)->IsFunction();
+
+ if (try_catch.HasCaught())
+ HandleError(try_catch.Message());
+
+ // The value should only be empty if an exception was thrown. Code
+ // defensively just in case.
+ DCHECK_EQ(function->IsEmpty(), try_catch.HasCaught());
+ if (function->IsEmpty() || try_catch.HasCaught()) {
+ js_bindings()->OnError(
+ -1,
+ base::ASCIIToUTF16("Accessing FindProxyForURL threw an exception."));
+ return ERR_PAC_SCRIPT_FAILED;
+ }
+
+ if (!(*function)->IsFunction()) {
+ js_bindings()->OnError(
+ -1, base::ASCIIToUTF16(
+ "FindProxyForURL is undefined or not a function."));
+ return ERR_PAC_SCRIPT_FAILED;
+ }
+
+ return OK;
}
// Handle an exception thrown by V8.

Powered by Google App Engine
This is Rietveld 408576698