Bug 813897 - Fix crash in URL Classifier when using a system principal. r=bsmith, r=dcamp, a=lsblakk
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 05 Mar 2013 10:39:37 +0100
changeset 132295 9d203380317cef7058890d667d65fed25610220c
parent 132294 dab60b543514d9129c5757b2a8dadad3fb0376cc
child 132296 6f7104a8561856282b5f14f2d2a97df49b69f705
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmith, dcamp, lsblakk
bugs813897
milestone21.0a2
Bug 813897 - Fix crash in URL Classifier when using a system principal. r=bsmith, r=dcamp, a=lsblakk
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/tests/mochitest/Makefile.in
toolkit/components/url-classifier/tests/mochitest/test_lookup_system_principal.html
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -37,16 +37,17 @@
 #include "prlog.h"
 #include "prprf.h"
 #include "prnetdb.h"
 #include "Entries.h"
 #include "mozilla/Attributes.h"
 #include "nsIPrincipal.h"
 #include "Classifier.h"
 #include "ProtocolParser.h"
+#include "nsContentUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::safebrowsing;
 
 // NSPR_LOG_MODULES=UrlClassifierDbService:5
 #if defined(PR_LOGGING)
 PRLogModuleInfo *gUrlClassifierDbServiceLog = nullptr;
 #define LOG(args) PR_LOG(gUrlClassifierDbServiceLog, PR_LOG_DEBUG, args)
@@ -1232,19 +1233,25 @@ nsresult
 nsUrlClassifierDBService::LookupURI(nsIPrincipal* aPrincipal,
                                     nsIUrlClassifierCallback* c,
                                     bool forceLookup,
                                     bool *didLookup)
 {
   NS_ENSURE_TRUE(gDbBackgroundThread, NS_ERROR_NOT_INITIALIZED);
   NS_ENSURE_ARG(aPrincipal);
 
+  if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
+    *didLookup = false;
+    return NS_OK;
+  }
+
   nsCOMPtr<nsIURI> uri;
   nsresult rv = aPrincipal->GetURI(getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
 
   uri = NS_GetInnermostURI(uri);
   NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
 
   nsAutoCString key;
   // Canonicalize the url
   nsCOMPtr<nsIUrlClassifierUtils> utilsService =
     do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
--- a/toolkit/components/url-classifier/tests/mochitest/Makefile.in
+++ b/toolkit/components/url-classifier/tests/mochitest/Makefile.in
@@ -20,9 +20,14 @@ MOCHITEST_FILES = \
 		workerFrame.html \
 		cleanWorker.js \
 		evil.js \
 		evilWorker.js \
 		evil.css \
 		import.css \
 		$(NULL)
 
+MOCHITEST_CHROME_FILES = \
+  test_lookup_system_principal.html \
+  $(NULL)
+
+
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/toolkit/components/url-classifier/tests/mochitest/test_lookup_system_principal.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test that lookup() on a system principal doesn't crash</title>
+  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+</head>
+
+<body>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+
+<script type="text/javascript">
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+
+var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
+                .getService(Ci.nsIUrlClassifierDBService);
+
+dbService.lookup(document.nodePrincipal, function(arg) {});
+
+ok(true, "lookup() didn't crash");
+
+</script>
+</pre>
+</body>
+</html>
\ No newline at end of file