Skip to content

Commit

Permalink
Bug 1781201 - Change GetInfoFromValidatedPrincipalInfo to be fallible…
Browse files Browse the repository at this point in the history
…; r=hsingh

The generation of unique anonynmous origins can fail, so the method needs to be
fallible as well, otherwise the failures couldn't be propagated.

Differential Revision: https://phabricator.services.mozilla.com/D176874
  • Loading branch information
janvarga committed May 3, 2023
1 parent a81f885 commit 1c695f7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 29 deletions.
5 changes: 4 additions & 1 deletion dom/cache/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,12 @@ Context::QuotaInitRunnable::Run() {
auto* const quotaManager = QuotaManager::Get();
MOZ_DIAGNOSTIC_ASSERT(quotaManager);

mDirectoryMetadata.emplace(
QM_TRY_UNWRAP(
auto principalMetadata,
quotaManager->GetInfoFromValidatedPrincipalInfo(*mPrincipalInfo));

mDirectoryMetadata.emplace(std::move(principalMetadata));

// Open directory
RefPtr<DirectoryLock> directoryLock = quotaManager->CreateDirectoryLock(
PERSISTENCE_TYPE_DEFAULT, *mDirectoryMetadata,
Expand Down
11 changes: 7 additions & 4 deletions dom/fs/parent/FileSystemManagerParentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ mozilla::ipc::IPCResult CreateFileSystemManagerParent(
[aResolver](const auto&) { aResolver(NS_ERROR_DOM_SECURITY_ERR); });

QM_TRY(quota::QuotaManager::EnsureCreated(), IPC_OK(),
[aResolver](const auto&) { aResolver(NS_ERROR_FAILURE); });
[aResolver](const auto rv) { aResolver(rv); });

auto* const quotaManager = quota::QuotaManager::Get();
MOZ_ASSERT(quotaManager);

quota::OriginMetadata originMetadata(
quotaManager->GetInfoFromValidatedPrincipalInfo(aPrincipalInfo),
quota::PERSISTENCE_TYPE_DEFAULT);
QM_TRY_UNWRAP(auto principalMetadata,
quotaManager->GetInfoFromValidatedPrincipalInfo(aPrincipalInfo),
IPC_OK(), [aResolver](const auto rv) { aResolver(rv); });

quota::OriginMetadata originMetadata(std::move(principalMetadata),
quota::PERSISTENCE_TYPE_DEFAULT);

// Block use for now in PrivateBrowsing
QM_TRY(OkIf(!OriginAttributes::IsPrivateBrowsing(originMetadata.mOrigin)),
Expand Down
8 changes: 5 additions & 3 deletions dom/indexedDB/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14942,9 +14942,11 @@ nsresult FactoryOp::FinishOpen() {
} else {
MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);

mOriginMetadata = {
quotaManager->GetInfoFromValidatedPrincipalInfo(principalInfo),
persistenceType};
QM_TRY_UNWRAP(
auto principalMetadata,
quotaManager->GetInfoFromValidatedPrincipalInfo(principalInfo));

mOriginMetadata = {std::move(principalMetadata), persistenceType};

mEnforcingQuota = persistenceType != PERSISTENCE_TYPE_PERSISTENT;
}
Expand Down
6 changes: 3 additions & 3 deletions dom/localstorage/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6671,9 +6671,9 @@ nsresult PrepareDatastoreOp::Start() {
MOZ_ASSERT(storagePrincipalInfo.type() ==
PrincipalInfo::TContentPrincipalInfo);

PrincipalMetadata principalMetadata =
QuotaManager::Get()->GetInfoFromValidatedPrincipalInfo(
storagePrincipalInfo);
QM_TRY_UNWRAP(auto principalMetadata,
QuotaManager::Get()->GetInfoFromValidatedPrincipalInfo(
storagePrincipalInfo));

mOriginMetadata.mSuffix = std::move(principalMetadata.mSuffix);
mOriginMetadata.mGroup = std::move(principalMetadata.mGroup);
Expand Down
37 changes: 23 additions & 14 deletions dom/quota/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6437,7 +6437,8 @@ bool QuotaManager::IsPrincipalInfoValid(const PrincipalInfo& aPrincipalInfo) {
return false;
}

PrincipalMetadata QuotaManager::GetInfoFromValidatedPrincipalInfo(
Result<PrincipalMetadata, nsresult>
QuotaManager::GetInfoFromValidatedPrincipalInfo(
const PrincipalInfo& aPrincipalInfo) {
MOZ_ASSERT(IsPrincipalInfoValid(aPrincipalInfo));

Expand Down Expand Up @@ -8388,8 +8389,9 @@ GetOriginUsageOp::GetOriginUsageOp(const UsageRequestParams& aParams)
nsresult GetOriginUsageOp::DoInit(QuotaManager& aQuotaManager) {
AssertIsOnOwningThread();

PrincipalMetadata principalMetadata =
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mParams.principalInfo());
QM_TRY_UNWRAP(
PrincipalMetadata principalMetadata,
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mParams.principalInfo()));
MOZ_ASSERT(principalMetadata.mOrigin == principalMetadata.mStorageOrigin);

mSuffix = std::move(principalMetadata.mSuffix);
Expand Down Expand Up @@ -8666,8 +8668,9 @@ void InitializeOriginRequestBase::Init(Quota& aQuota) {
nsresult InitializeOriginRequestBase::DoInit(QuotaManager& aQuotaManager) {
AssertIsOnOwningThread();

auto principalMetadata =
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mPrincipalInfo);
QM_TRY_UNWRAP(
auto principalMetadata,
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mPrincipalInfo));
MOZ_ASSERT(principalMetadata.mOrigin == principalMetadata.mStorageOrigin);

mSuffix = std::move(principalMetadata.mSuffix);
Expand Down Expand Up @@ -8767,8 +8770,9 @@ GetFullOriginMetadataOp::GetFullOriginMetadataOp(
nsresult GetFullOriginMetadataOp::DoInit(QuotaManager& aQuotaManager) {
AssertIsOnOwningThread();

PrincipalMetadata principalMetadata =
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mParams.principalInfo());
QM_TRY_UNWRAP(
PrincipalMetadata principalMetadata,
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mParams.principalInfo()));
MOZ_ASSERT(principalMetadata.mOrigin == principalMetadata.mStorageOrigin);

mOriginMetadata = {std::move(principalMetadata), mParams.persistenceType()};
Expand Down Expand Up @@ -9277,8 +9281,9 @@ nsresult PersistRequestBase::DoInit(QuotaManager& aQuotaManager) {
AssertIsOnOwningThread();

// Figure out which origin we're dealing with.
PrincipalMetadata principalMetadata =
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mPrincipalInfo);
QM_TRY_UNWRAP(
PrincipalMetadata principalMetadata,
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mPrincipalInfo));
MOZ_ASSERT(principalMetadata.mOrigin == principalMetadata.mStorageOrigin);

mSuffix = std::move(principalMetadata.mSuffix);
Expand Down Expand Up @@ -9440,8 +9445,9 @@ EstimateOp::EstimateOp(const EstimateParams& aParams)
nsresult EstimateOp::DoInit(QuotaManager& aQuotaManager) {
AssertIsOnOwningThread();

PrincipalMetadata principalMetadata =
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mParams.principalInfo());
QM_TRY_UNWRAP(
PrincipalMetadata principalMetadata,
aQuotaManager.GetInfoFromValidatedPrincipalInfo(mParams.principalInfo()));
MOZ_ASSERT(principalMetadata.mOrigin == principalMetadata.mStorageOrigin);

mOriginMetadata = {std::move(principalMetadata), PERSISTENCE_TYPE_DEFAULT};
Expand Down Expand Up @@ -9880,9 +9886,12 @@ nsresult StorageOperationBase::ProcessOriginDirectories() {

PrincipalInfo principalInfo(contentPrincipalInfo);

originProps.mOriginMetadata = {
quotaManager->GetInfoFromValidatedPrincipalInfo(principalInfo),
*originProps.mPersistenceType};
QM_TRY_UNWRAP(
auto principalMetadata,
quotaManager->GetInfoFromValidatedPrincipalInfo(principalInfo));

originProps.mOriginMetadata = {std::move(principalMetadata),
*originProps.mPersistenceType};

#ifdef QM_PRINCIPALINFO_VERIFICATION_ENABLED
principalInfos.AppendElement(principalInfo);
Expand Down
2 changes: 1 addition & 1 deletion dom/quota/QuotaManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class QuotaManager final : public BackgroundThreadObject {

static bool IsPrincipalInfoValid(const PrincipalInfo& aPrincipalInfo);

PrincipalMetadata GetInfoFromValidatedPrincipalInfo(
Result<PrincipalMetadata, nsresult> GetInfoFromValidatedPrincipalInfo(
const PrincipalInfo& aPrincipalInfo);

static nsAutoCString GetOriginFromValidatedPrincipalInfo(
Expand Down
8 changes: 5 additions & 3 deletions dom/simpledb/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,11 @@ nsresult OpenOp::FinishOpen() {
} else {
MOZ_ASSERT(principalInfo.type() == PrincipalInfo::TContentPrincipalInfo);

mOriginMetadata = {
quotaManager->GetInfoFromValidatedPrincipalInfo(principalInfo),
persistenceType};
QM_TRY_UNWRAP(
auto principalMetadata,
quotaManager->GetInfoFromValidatedPrincipalInfo(principalInfo));

mOriginMetadata = {std::move(principalMetadata), persistenceType};
}

if (gOpenConnections) {
Expand Down

0 comments on commit 1c695f7

Please sign in to comment.