Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 29ccb54

Browse files
committed
Bug 1641611 - PermissionManager should take the largest ID considering the expired permissions too, r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D92887
1 parent 0f89989 commit 29ccb54

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

extensions/permissions/PermissionManager.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,8 +2690,19 @@ nsresult PermissionManager::Read(const MonitorAutoLock& aProofOfLock) {
26902690
auto data = mThreadBoundData.Access();
26912691

26922692
nsresult rv;
2693-
2693+
bool hasResult;
26942694
nsCOMPtr<mozIStorageStatement> stmt;
2695+
2696+
// Let's retrieve the last used ID.
2697+
rv = data->mDBConn->CreateStatement(
2698+
nsLiteralCString("SELECT MAX(id) FROM moz_perms"), getter_AddRefs(stmt));
2699+
NS_ENSURE_SUCCESS(rv, rv);
2700+
2701+
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
2702+
int64_t id = stmt->AsInt64(0);
2703+
mLargestID = id;
2704+
}
2705+
26952706
rv = data->mDBConn->CreateStatement(
26962707
nsLiteralCString(
26972708
"SELECT id, origin, type, permission, expireType, "
@@ -2706,7 +2717,6 @@ nsresult PermissionManager::Read(const MonitorAutoLock& aProofOfLock) {
27062717
rv = stmt->BindInt64ByIndex(1, EXPIRY_NOW);
27072718
NS_ENSURE_SUCCESS(rv, rv);
27082719

2709-
bool hasResult;
27102720
bool readError = false;
27112721

27122722
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
@@ -2715,7 +2725,7 @@ nsresult PermissionManager::Read(const MonitorAutoLock& aProofOfLock) {
27152725
// explicitly set our entry id counter for use in AddInternal(),
27162726
// and keep track of the largest id so we know where to pick up.
27172727
entry.mId = stmt->AsInt64(0);
2718-
if (entry.mId > mLargestID) mLargestID = entry.mId;
2728+
MOZ_ASSERT(entry.mId <= mLargestID);
27192729

27202730
rv = stmt->GetUTF8String(1, entry.mOrigin);
27212731
if (NS_FAILED(rv)) {

0 commit comments

Comments
 (0)