Bug 1548517 - Add hash for test entries added via HostInPrefTables. r=baku
authordlee <dlee@mozilla.com>
Fri, 10 May 2019 19:39:24 +0000
changeset 532573 ca347ea97ee31b859bc250936cf6e4256198c516
parent 532572 28912333e8b808d478f432ca66bc6349c3624349
child 532574 18ce39639db8395584fb8dbd8fc0927c90228291
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1548517
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548517 - Add hash for test entries added via HostInPrefTables. r=baku Origin telemetry expects every tracking channel has tracker's hash. Without hash value for test entries, it will trigger MOZ_ASSERT while running testcases. Differential Revision: https://phabricator.services.mozilla.com/D30061
netwerk/url-classifier/AsyncUrlChannelClassifier.cpp
toolkit/components/url-classifier/Entries.h
--- a/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp
+++ b/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp
@@ -428,25 +428,33 @@ bool FeatureData::MaybeCompleteClassific
     UC_LOG(
         ("FeatureData::MaybeCompleteClassification[%p] - uri found in skiplist",
          this));
     return true;
   }
 
   nsTArray<nsCString> list;
   nsTArray<nsCString> hashes;
-  list.AppendElement(mHostInPrefTables[nsIUrlClassifierFeature::blacklist]);
+  if (!mHostInPrefTables[nsIUrlClassifierFeature::blacklist].IsEmpty()) {
+    list.AppendElement(mHostInPrefTables[nsIUrlClassifierFeature::blacklist]);
+
+    // Telemetry expects every tracking channel has hash, create it for test
+    // entry
+    Completion complete;
+    complete.FromPlaintext(
+        mHostInPrefTables[nsIUrlClassifierFeature::blacklist]);
+    hashes.AppendElement(complete.ToString());
+  }
 
   for (TableData* tableData : mBlacklistTables) {
     if (tableData->MatchState() == TableData::eMatch) {
       list.AppendElement(tableData->Table());
 
       for (const auto& r : tableData->Result()) {
-        nsCString* hash = hashes.AppendElement();
-        r->hash.complete.ToString(*hash);
+        hashes.AppendElement(r->hash.complete.ToString());
       }
     }
   }
 
   UC_LOG(("FeatureData::MaybeCompleteClassification[%p] - process channel %p",
           this, aChannel));
 
   bool shouldContinue = false;
--- a/toolkit/components/url-classifier/Entries.h
+++ b/toolkit/components/url-classifier/Entries.h
@@ -81,23 +81,30 @@ struct SafebrowsingHash {
     return Comparator::Compare(buf, aOther.buf) != 0;
   }
 
   bool operator<(const self_type& aOther) const {
     return Comparator::Compare(buf, aOther.buf) < 0;
   }
 
   void ToString(nsACString& aStr) const {
+    // Base64 represents 6-bits data as 8-bits output.
     uint32_t len = ((sHashSize + 2) / 3) * 4;
 
     aStr.SetLength(len);
     PL_Base64Encode((char*)buf, sHashSize, aStr.BeginWriting());
     MOZ_ASSERT(aStr.BeginReading()[len] == '\0');
   }
 
+  nsCString ToString() const {
+    nsAutoCString str;
+    ToString(str);
+    return std::move(str);
+  }
+
   void ToHexString(nsACString& aStr) const {
     static const char* const lut = "0123456789ABCDEF";
     // 32 bytes is the longest hash
     size_t len = 32;
 
     aStr.SetCapacity(2 * len);
     for (size_t i = 0; i < len; ++i) {
       const char c = static_cast<char>(buf[i]);