Bug 1562837 - Ensure that the fields stored in the nsHttpConnectionInfo hash key are properly preserved when rebuilding it upon a change to the isolation flag; r=michal a=RyanVM
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 09 Jul 2019 14:28:44 +0000
changeset 544471 36dd2e9d0477df07490746bae9a39029925dc568
parent 544470 0aa0865a4011004e2966c14b9cecc5991b584b3d
child 544472 fbf6b76ff06f46dfd0adc9c98545a9682432db95
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal, RyanVM
bugs1562837
milestone69.0
Bug 1562837 - Ensure that the fields stored in the nsHttpConnectionInfo hash key are properly preserved when rebuilding it upon a change to the isolation flag; r=michal a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D37321
netwerk/protocol/http/nsHttpConnectionInfo.cpp
netwerk/protocol/http/nsHttpConnectionInfo.h
--- a/netwerk/protocol/http/nsHttpConnectionInfo.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionInfo.cpp
@@ -149,16 +149,19 @@ void nsHttpConnectionInfo::BuildHashKey(
   // byte 0 is P/T/. {P,T} for Plaintext/TLS Proxy over HTTP
   // byte 1 is S/. S is for end to end ssl such as https:// uris
   // byte 2 is A/. A is for an anonymous channel (no cookies, etc..)
   // byte 3 is P/. P is for a private browising channel
   // byte 4 is I/. I is for insecure scheme on TLS for http:// uris
   // byte 5 is X/. X is for disallow_spdy flag
   // byte 6 is C/. C is for be Conservative
   // byte 7 is i/. i is for isolated
+  // Note: when adding/removing fields from this list which do not have
+  // corresponding data fields on the object itself, you may also need to
+  // modify RebuildHashKey.
 
   mHashKey.AssignLiteral("........[tlsflags0x00000000]");
   if (mIsolated) {
     mHashKey.SetCharAt('i', 7);
   }
 
   mHashKey.Append(keyHost);
   mHashKey.Append(':');
@@ -262,20 +265,41 @@ void nsHttpConnectionInfo::BuildHashKey(
     }
   }
 
   nsAutoCString originAttributes;
   mOriginAttributes.CreateSuffix(originAttributes);
   mHashKey.Append(originAttributes);
 }
 
+void nsHttpConnectionInfo::RebuildHashKey() {
+  // Create copies of all properties stored in our hash key.
+  bool isAnonymous = GetAnonymous();
+  bool isPrivate = GetPrivate();
+  bool isInsecureScheme = GetInsecureScheme();
+  bool isNoSpdy = GetNoSpdy();
+  bool isBeConservative = GetBeConservative();
+
+  BuildHashKey();
+
+  // Restore all of those properties.
+  SetAnonymous(isAnonymous);
+  SetPrivate(isPrivate);
+  SetInsecureScheme(isInsecureScheme);
+  SetNoSpdy(isNoSpdy);
+  SetBeConservative(isBeConservative);
+}
+
 void nsHttpConnectionInfo::SetOriginServer(const nsACString& host,
                                            int32_t port) {
   mOrigin = host;
   mOriginPort = port == -1 ? DefaultPort() : port;
+  // Use BuildHashKey() since this can only be called when constructing an
+  // nsHttpConnectionInfo object.
+  MOZ_DIAGNOSTIC_ASSERT(mHashKey.IsEmpty());
   BuildHashKey();
 }
 
 already_AddRefed<nsHttpConnectionInfo> nsHttpConnectionInfo::Clone() const {
   RefPtr<nsHttpConnectionInfo> clone;
   if (mRoutedHost.IsEmpty()) {
     clone = new nsHttpConnectionInfo(
         mOrigin, mOriginPort, mNPNToken, mUsername, mTopWindowOrigin,
@@ -346,31 +370,31 @@ nsresult nsHttpConnectionInfo::CreateWil
   clone->SetPrivate(GetPrivate());
   clone.forget(outParam);
   return NS_OK;
 }
 
 void nsHttpConnectionInfo::SetTrrDisabled(bool aNoTrr) {
   if (mTrrDisabled != aNoTrr) {
     mTrrDisabled = aNoTrr;
-    BuildHashKey();
+    RebuildHashKey();
   }
 }
 
 void nsHttpConnectionInfo::SetIPv4Disabled(bool aNoIPv4) {
   if (mIPv4Disabled != aNoIPv4) {
     mIPv4Disabled = aNoIPv4;
-    BuildHashKey();
+    RebuildHashKey();
   }
 }
 
 void nsHttpConnectionInfo::SetIPv6Disabled(bool aNoIPv6) {
   if (mIPv6Disabled != aNoIPv6) {
     mIPv6Disabled = aNoIPv6;
-    BuildHashKey();
+    RebuildHashKey();
   }
 }
 
 void nsHttpConnectionInfo::SetTlsFlags(uint32_t aTlsFlags) {
   mTlsFlags = aTlsFlags;
 
   mHashKey.Replace(19, 8, nsPrintfCString("%08x", mTlsFlags));
 }
--- a/netwerk/protocol/http/nsHttpConnectionInfo.h
+++ b/netwerk/protocol/http/nsHttpConnectionInfo.h
@@ -55,16 +55,17 @@ class nsHttpConnectionInfo final : publi
 
  private:
   virtual ~nsHttpConnectionInfo() {
     MOZ_LOG(gHttpLog, LogLevel::Debug,
             ("Destroying nsHttpConnectionInfo @%p\n", this));
   }
 
   void BuildHashKey();
+  void RebuildHashKey();
 
  public:
   const nsCString& HashKey() const { return mHashKey; }
 
   const nsCString& GetOrigin() const { return mOrigin; }
   const char* Origin() const { return mOrigin.get(); }
   int32_t OriginPort() const { return mOriginPort; }
 
@@ -128,17 +129,17 @@ class nsHttpConnectionInfo final : publi
 
   void SetBeConservative(bool aBeConservative) {
     mHashKey.SetCharAt(aBeConservative ? 'C' : '.', 6);
   }
   bool GetBeConservative() const { return mHashKey.CharAt(6) == 'C'; }
 
   void SetIsolated(bool aIsolated) {
     mIsolated = aIsolated;
-    BuildHashKey();
+    RebuildHashKey();
   }
   bool GetIsolated() const { return mIsolated; }
 
   void SetTlsFlags(uint32_t aTlsFlags);
   uint32_t GetTlsFlags() const { return mTlsFlags; }
 
   // IsTrrServiceChannel means that this connection is used to send TRR requests
   // over