Bug 1536387 - Append a regular HTTP cache key tag of value 0x7f to distinguish memory-only entries, enhance the range for allowed http cache storage key tag character values, r=michal a=pascalc
authorHonza Bambas <honzab.moz@firemni.cz>
Wed, 03 Apr 2019 16:36:30 +0300
changeset 525897 d32f0c0ddb193cafc7ce89a1a4fe5000db4d6e38
parent 525896 a3b5dd595e17ef9b32ec4c806560362ca2347526
child 525898 734b7738a6c485a6fd11099fdd9a14920d32b21d
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal, pascalc
bugs1536387
milestone67.0
Bug 1536387 - Append a regular HTTP cache key tag of value 0x7f to distinguish memory-only entries, enhance the range for allowed http cache storage key tag character values, r=michal a=pascalc
netwerk/cache2/CacheFileUtils.cpp
netwerk/cache2/CacheStorageService.cpp
--- a/netwerk/cache2/CacheFileUtils.cpp
+++ b/netwerk/cache2/CacheFileUtils.cpp
@@ -42,18 +42,23 @@ class KeyParser : protected Tokenizer {
   OriginAttributes originAttribs;
   bool isAnonymous;
   nsCString idEnhance;
   nsDependentCSubstring cacheKey;
 
   // Keeps the last tag name, used for alphabetical sort checking
   char lastTag;
 
-  // Classifier for the 'tag' character valid range
-  static bool TagChar(const char aChar) { return aChar >= ' ' && aChar <= '~'; }
+  // Classifier for the 'tag' character valid range.
+  // Explicitly using unsigned char as 127 is -1 when signed and it would only
+  // produce a warning.
+  static bool TagChar(const char aChar) {
+    unsigned char c = static_cast<unsigned char>(aChar);
+    return c >= ' ' && c <= '\x7f';
+  }
 
   bool ParseTags() {
     // Expects to be at the tag name or at the end
     if (CheckEOF()) {
       return true;
     }
 
     char tag;
--- a/netwerk/cache2/CacheStorageService.cpp
+++ b/netwerk/cache2/CacheStorageService.cpp
@@ -35,19 +35,20 @@
 #include "mozilla/Services.h"
 #include "mozilla/IntegerPrintfMacros.h"
 
 namespace mozilla {
 namespace net {
 
 namespace {
 
-void AppendMemoryStorageID(nsAutoCString& key) {
-  key.Append('/');
-  key.Append('M');
+void AppendMemoryStorageTag(nsAutoCString& key) {
+  // Using DEL as the very last ascii-7 character we can use in the list of attributes
+  key.Append('\x7f');
+  key.Append(',');
 }
 
 }  // namespace
 
 // Not defining as static or class member of CacheStorageService since
 // it would otherwise need to include CacheEntry.h and that then would
 // need to be exported to make nsNetModule.cpp compilable.
 typedef nsClassHashtable<nsCStringHashKey, CacheEntryTable> GlobalEntryTables;
@@ -1055,17 +1056,17 @@ bool CacheStorageService::RemoveEntry(Ca
     }
   }
 
   CacheEntryTable* entries;
   if (sGlobalEntryTables->Get(aEntry->GetStorageID(), &entries))
     RemoveExactEntry(entries, entryKey, aEntry, false /* don't overwrite */);
 
   nsAutoCString memoryStorageID(aEntry->GetStorageID());
-  AppendMemoryStorageID(memoryStorageID);
+  AppendMemoryStorageTag(memoryStorageID);
 
   if (sGlobalEntryTables->Get(memoryStorageID, &entries))
     RemoveExactEntry(entries, entryKey, aEntry, false /* don't overwrite */);
 
   return true;
 }
 
 void CacheStorageService::RecordMemoryOnlyEntry(CacheEntry* aEntry,
@@ -1094,17 +1095,17 @@ void CacheStorageService::RecordMemoryOn
   rv = aEntry->HashingKey(entryKey);
   if (NS_FAILED(rv)) {
     NS_ERROR("aEntry->HashingKey() failed?");
     return;
   }
 
   CacheEntryTable* entries = nullptr;
   nsAutoCString memoryStorageID(aEntry->GetStorageID());
-  AppendMemoryStorageID(memoryStorageID);
+  AppendMemoryStorageTag(memoryStorageID);
 
   if (!sGlobalEntryTables->Get(memoryStorageID, &entries)) {
     if (!aOnlyInMemory) {
       LOG(("  not recorded as memory only"));
       return;
     }
 
     entries = new CacheEntryTable(CacheEntryTable::MEMORY_ONLY);
@@ -1523,17 +1524,17 @@ nsresult CacheStorageService::CheckStora
                                                 const nsACString& aIdExtension,
                                                 bool* aResult) {
   nsresult rv;
 
   nsAutoCString contextKey;
   CacheFileUtils::AppendKeyPrefix(aStorage->LoadInfo(), contextKey);
 
   if (!aStorage->WriteToDisk()) {
-    AppendMemoryStorageID(contextKey);
+    AppendMemoryStorageTag(contextKey);
   }
 
   LOG(("CacheStorageService::CheckStorageEntry [uri=%s, eid=%s, contextKey=%s]",
        aURI.BeginReading(), aIdExtension.BeginReading(), contextKey.get()));
 
   {
     mozilla::MutexAutoLock lock(mLock);
 
@@ -1796,17 +1797,17 @@ nsresult CacheStorageService::DoomStorag
   LOG(("CacheStorageService::DoomStorageEntries [context=%s]",
        aContextKey.BeginReading()));
 
   mLock.AssertCurrentThreadOwns();
 
   NS_ENSURE_TRUE(!mShutdown, NS_ERROR_NOT_INITIALIZED);
 
   nsAutoCString memoryStorageID(aContextKey);
-  AppendMemoryStorageID(memoryStorageID);
+  AppendMemoryStorageTag(memoryStorageID);
 
   if (aDiskStorage) {
     LOG(("  dooming disk+memory storage of %s", aContextKey.BeginReading()));
 
     // Walk one by one and remove entries according their pin status
     CacheEntryTable *diskEntries, *memoryEntries;
     if (sGlobalEntryTables->Get(aContextKey, &diskEntries)) {
       sGlobalEntryTables->Get(memoryStorageID, &memoryEntries);