Bug 1575842 - Do not use |ResetTables| when detecting Safe Browing database corruption in GetLookupCache. r=gcp

This patch replaces |ResetTables|(clear table's in-memory and on-disk
data) with |DeleteTables|(clear table's on-disk data) in GetLookupCache to avoid infinite
loop.

We can just delete on-disk data when file corruption is detected in |GetLookupCache|
without clearing the cache's internal data and refreshing current
active caches because in that scenario, the lookup cache failing to read
database has not yet added to the active caches list.

Differential Revision: https://phabricator.services.mozilla.com/D43181
This commit is contained in:
dlee
2019-08-23 08:19:18 +00:00
parent 565479bb88
commit 4fc32e69a6

View File

@@ -362,6 +362,9 @@ void Classifier::ResetTables(ClearType aType,
}
}
// |DeleteTables| is used by |GetLookupCache| to remove on-disk data when
// we detect prefix file corruption. So make sure not to call |GetLookupCache|
// again in this function to avoid infinite loop.
void Classifier::DeleteTables(nsIFile* aDirectory,
const nsTArray<nsCString>& aTables) {
nsCOMPtr<nsIDirectoryEnumerator> entries;
@@ -1566,7 +1569,8 @@ RefPtr<LookupCache> Classifier::GetLookupCache(const nsACString& aTable,
// Remove all the on-disk data when the table's prefix file is corrupted.
LOG(("Failed to get prefixes from file for table %s, delete on-disk data!",
aTable.BeginReading()));
ResetTables(Clear_All, nsTArray<nsCString>{nsCString(aTable)});
DeleteTables(mRootStoreDirectory, nsTArray<nsCString>{nsCString(aTable)});
}
return nullptr;
}