Bug 1300720 - Part 1: Prevent file:, chrome: and resource: URIs from using an external protocol handler. r=honza, a=ritu
authorCameron McCormack <cam@mcc.id.au>
Mon, 03 Oct 2016 12:43:15 +0800
changeset 350590 96f026e37e8d1b9740ebece310b94105596a315c
parent 350589 3bf677e1bd15cbf8ae2df81299ceb134074da778
child 350591 551a639bcec6c15efaa2bd6b9511d623affac14f
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonza, ritu
bugs1300720
milestone50.0
Bug 1300720 - Part 1: Prevent file:, chrome: and resource: URIs from using an external protocol handler. r=honza, a=ritu MozReview-Commit-ID: 51r5lObSRwx
netwerk/base/nsIOService.cpp
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -493,43 +493,49 @@ nsIOService::GetCachedProtocolHandler(co
                 : (!nsCRT::strcasecmp(scheme, gScheme[i])))
         {
             return CallQueryReferent(mWeakHandler[i].get(), result);
         }
     }
     return NS_ERROR_FAILURE;
 }
  
+static bool
+UsesExternalProtocolHandler(const char* aScheme)
+{
+    if (NS_LITERAL_CSTRING("file").Equals(aScheme) ||
+        NS_LITERAL_CSTRING("chrome").Equals(aScheme) ||
+        NS_LITERAL_CSTRING("resource").Equals(aScheme)) {
+        // Don't allow file:, chrome: or resource: URIs to be handled with
+        // nsExternalProtocolHandler, since internally we rely on being able to
+        // use and read from these URIs.
+        return false;
+    }
+
+    nsAutoCString pref("network.protocol-handler.external.");
+    pref += aScheme;
+
+    return Preferences::GetBool(pref.get(), false);
+}
+
 NS_IMETHODIMP
 nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
 {
     nsresult rv;
 
     NS_ENSURE_ARG_POINTER(scheme);
     // XXX we may want to speed this up by introducing our own protocol 
     // scheme -> protocol handler mapping, avoiding the string manipulation
     // and service manager stuff
 
     rv = GetCachedProtocolHandler(scheme, result);
     if (NS_SUCCEEDED(rv))
         return rv;
 
-    bool externalProtocol = false;
-    nsCOMPtr<nsIPrefBranch> prefBranch;
-    GetPrefBranch(getter_AddRefs(prefBranch));
-    if (prefBranch) {
-        nsAutoCString externalProtocolPref("network.protocol-handler.external.");
-        externalProtocolPref += scheme;
-        rv = prefBranch->GetBoolPref(externalProtocolPref.get(), &externalProtocol);
-        if (NS_FAILED(rv)) {
-            externalProtocol = false;
-        }
-    }
-
-    if (!externalProtocol) {
+    if (!UsesExternalProtocolHandler(scheme)) {
         nsAutoCString contractID(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX);
         contractID += scheme;
         ToLowerCase(contractID);
 
         rv = CallGetService(contractID.get(), result);
         if (NS_SUCCEEDED(rv)) {
             CacheProtocolHandler(scheme, *result);
             return rv;