Bug 1553963 - Fix Safe Browsing doesn't cache the gethash result for V4 tables. r=gcp a=jcristau
authordlee <dlee@mozilla.com>
Fri, 24 May 2019 19:42:00 +0000
changeset 536512 bc9fed12c6e8f969337d00af730585d5590ce302
parent 536511 884c684970a24cb564377b8a18beef4373e7babf
child 536513 0a91cbfe3b3fa04f0af0adcaff33c8dc3b4a345d
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp, jcristau
bugs1553963, 1353956
milestone68.0
Bug 1553963 - Fix Safe Browsing doesn't cache the gethash result for V4 tables. r=gcp a=jcristau We use ".pset" to find active tables, but in Bug 1353956, v4 prefix files are renamed to ".vlpset". This patches include both 'pset' and 'vlpset' to ScanStoreDir. Differential Revision: https://phabricator.services.mozilla.com/D32433
toolkit/components/url-classifier/Classifier.cpp
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -917,27 +917,27 @@ nsresult Classifier::ScanStoreDir(nsIFil
     if (NS_FAILED(file->IsDirectory(&isDirectory))) {
       continue;
     }
     if (isDirectory) {
       ScanStoreDir(file, aTables);
       continue;
     }
 
-    nsCString leafName;
+    nsAutoCString leafName;
     rv = file->GetNativeLeafName(leafName);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // Both v2 and v4 contain .pset file
-    nsCString suffix(NS_LITERAL_CSTRING(".pset"));
-
-    int32_t dot = leafName.RFind(suffix);
-    if (dot != -1) {
-      leafName.Cut(dot, suffix.Length());
-      aTables.AppendElement(leafName);
+    // Check both V2 and V4 prefix files
+    if (StringEndsWith(leafName, NS_LITERAL_CSTRING(".pset"))) {
+      aTables.AppendElement(
+          Substring(leafName, 0, leafName.Length() - strlen(".pset")));
+    } else if (StringEndsWith(leafName, NS_LITERAL_CSTRING(".vlpset"))) {
+      aTables.AppendElement(
+          Substring(leafName, 0, leafName.Length() - strlen(".vlpset")));
     }
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult Classifier::ActiveTables(nsTArray<nsCString>& aTables) const {