From 1d98ea9a1603eeba33457d16405f423a039c9303 Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Wed, 21 Jul 2021 12:10:58 +0000 Subject: [PATCH] Bug 1719838 - Assert that OriginAttributes are pristine in PopulateFromSuffix. r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D120381 --- caps/OriginAttributes.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/caps/OriginAttributes.cpp b/caps/OriginAttributes.cpp index 71b4d5780eb0..7ac190abf481 100644 --- a/caps/OriginAttributes.cpp +++ b/caps/OriginAttributes.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/OriginAttributes.h" +#include "mozilla/Assertions.h" #include "mozilla/Preferences.h" #include "mozilla/dom/BlobURLProtocolHandler.h" #include "mozilla/dom/quota/QuotaManager.h" @@ -289,6 +290,14 @@ bool OriginAttributes::PopulateFromSuffix(const nsACString& aStr) { // to the suffix. Set to default before iterating to fix this. mPrivateBrowsingId = nsIScriptSecurityManager::DEFAULT_PRIVATE_BROWSING_ID; + // Checking that we are in a pristine state + + MOZ_RELEASE_ASSERT(mUserContextId == 0); + MOZ_RELEASE_ASSERT(mPrivateBrowsingId == 0); + MOZ_RELEASE_ASSERT(mFirstPartyDomain.IsEmpty()); + MOZ_RELEASE_ASSERT(mGeckoViewSessionContextId.IsEmpty()); + MOZ_RELEASE_ASSERT(mPartitionKey.IsEmpty()); + return URLParams::Parse( Substring(aStr, 1, aStr.Length() - 1), [this](const nsAString& aName, const nsAString& aValue) { @@ -328,7 +337,6 @@ bool OriginAttributes::PopulateFromSuffix(const nsACString& aStr) { } if (aName.EqualsLiteral("firstPartyDomain")) { - MOZ_RELEASE_ASSERT(mFirstPartyDomain.IsEmpty()); nsAutoString firstPartyDomain(aValue); firstPartyDomain.ReplaceChar(kSanitizedChar, kSourceChar); mFirstPartyDomain.Assign(firstPartyDomain); @@ -336,13 +344,11 @@ bool OriginAttributes::PopulateFromSuffix(const nsACString& aStr) { } if (aName.EqualsLiteral("geckoViewUserContextId")) { - MOZ_RELEASE_ASSERT(mGeckoViewSessionContextId.IsEmpty()); mGeckoViewSessionContextId.Assign(aValue); return true; } if (aName.EqualsLiteral("partitionKey")) { - MOZ_RELEASE_ASSERT(mPartitionKey.IsEmpty()); nsAutoString partitionKey(aValue); partitionKey.ReplaceChar(kSanitizedChar, kSourceChar); mPartitionKey.Assign(partitionKey);