From 2f472ac6fbdecd400a8ebbe12637f83fe093aa97 Mon Sep 17 00:00:00 2001 From: Mike Kaply Date: Mon, 28 Sep 2015 08:04:47 -0500 Subject: [PATCH] Bug 1193625 - Fallback to ASCII if AutoConfig UTF-8 conversion fails. r=Mossop, mrbkap --- .../pref/autoconfig/src/nsJSConfigTriggers.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp index e2339ebefaa..4da1c1fa433 100644 --- a/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp +++ b/extensions/pref/autoconfig/src/nsJSConfigTriggers.cpp @@ -16,6 +16,7 @@ #include "nsContentUtils.h" #include "nsIScriptSecurityManager.h" #include "nsJSPrincipals.h" +#include "nsIScriptError.h" #include "jswrapper.h" extern PRLogModuleInfo *MCD; @@ -106,7 +107,18 @@ nsresult EvaluateAdminConfigScript(const char *js_buffer, size_t length, nsAutoCString script(js_buffer, length); JS::RootedValue v(cx); - rv = xpc->EvalInSandboxObject(NS_ConvertUTF8toUTF16(script), filename, cx, + + nsString convertedScript = NS_ConvertUTF8toUTF16(script); + if (convertedScript.Length() == 0) { + nsContentUtils::ReportToConsoleNonLocalized( + NS_LITERAL_STRING("Your AutoConfig file is ASCII. Please convert it to UTF-8."), + nsIScriptError::warningFlag, + NS_LITERAL_CSTRING("autoconfig"), + nullptr); + /* If the length is 0, the conversion failed. Fallback to ASCII */ + convertedScript = NS_ConvertASCIItoUTF16(script); + } + rv = xpc->EvalInSandboxObject(convertedScript, filename, cx, autoconfigSb, JSVERSION_LATEST, &v); NS_ENSURE_SUCCESS(rv, rv);