From 581125e850bbac0673c3af58f3a64e1795f08666 Mon Sep 17 00:00:00 2001 From: Cykesiopka Date: Fri, 30 Oct 2015 07:50:09 -0700 Subject: [PATCH] Bug 1186817 - Replace nsBaseHashtable::EnumerateRead() calls in security/ with iterators. r=keeler --HG-- extra : histedit_source : ec44c79c05d3fb73cd720a9d5315ff781af812f1 --- security/manager/ssl/DataStorage.cpp | 52 +++++++++++----------------- security/manager/ssl/DataStorage.h | 4 --- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/security/manager/ssl/DataStorage.cpp b/security/manager/ssl/DataStorage.cpp index ce81ab879c32..6072cb65dee4 100644 --- a/security/manager/ssl/DataStorage.cpp +++ b/security/manager/ssl/DataStorage.cpp @@ -405,19 +405,6 @@ DataStorage::GetTableForType(DataStorageType aType, MOZ_CRASH("given bad DataStorage storage type"); } -// NB: The lock must be held when calling this function. -/* static */ -PLDHashOperator -DataStorage::EvictCallback(const nsACString& aKey, Entry aEntry, void* aArg) -{ - KeyAndEntry* toEvict = (KeyAndEntry*)aArg; - if (aEntry.mScore < toEvict->mEntry.mScore) { - toEvict->mKey = aKey; - toEvict->mEntry = aEntry; - } - return PLDHashOperator::PL_DHASH_NEXT; -} - // Limit the number of entries per table. This is to prevent unbounded // resource use. The eviction strategy is as follows: // - An entry's score is incremented once for every day it is accessed. @@ -442,7 +429,15 @@ DataStorage::MaybeEvictOneEntry(DataStorageType aType, // ultimately not that concerning, considering that if an attacker can // modify data in the profile, they can cause much worse harm. toEvict.mEntry.mScore = sMaxScore; - table.EnumerateRead(EvictCallback, (void*)&toEvict); + + for (auto iter = table.Iter(); !iter.Done(); iter.Next()) { + Entry entry = iter.UserData(); + if (entry.mScore < toEvict.mEntry.mScore) { + toEvict.mKey = iter.Key(); + toEvict.mEntry = entry; + } + } + table.Remove(toEvict.mKey); } } @@ -573,23 +568,6 @@ DataStorage::Writer::Run() return NS_OK; } -// NB: The lock must be held when calling this function. -/* static */ -PLDHashOperator -DataStorage::WriteDataCallback(const nsACString& aKey, Entry aEntry, void* aArg) -{ - nsCString* output = (nsCString*)aArg; - output->Append(aKey); - output->Append('\t'); - output->AppendInt(aEntry.mScore); - output->Append('\t'); - output->AppendInt(aEntry.mLastAccessed); - output->Append('\t'); - output->Append(aEntry.mValue); - output->Append('\n'); - return PLDHashOperator::PL_DHASH_NEXT; -} - nsresult DataStorage::AsyncWriteData(const MutexAutoLock& /*aProofOfLock*/) { @@ -598,7 +576,17 @@ DataStorage::AsyncWriteData(const MutexAutoLock& /*aProofOfLock*/) } nsCString output; - mPersistentDataTable.EnumerateRead(WriteDataCallback, (void*)&output); + for (auto iter = mPersistentDataTable.Iter(); !iter.Done(); iter.Next()) { + Entry entry = iter.UserData(); + output.Append(iter.Key()); + output.Append('\t'); + output.AppendInt(entry.mScore); + output.Append('\t'); + output.AppendInt(entry.mLastAccessed); + output.Append('\t'); + output.Append(entry.mValue); + output.Append('\n'); + } RefPtr job(new Writer(output, this)); nsresult rv = mWorkerThread->Dispatch(job, NS_DISPATCH_NORMAL); diff --git a/security/manager/ssl/DataStorage.h b/security/manager/ssl/DataStorage.h index 2dd658a451ed..ca9e11207346 100644 --- a/security/manager/ssl/DataStorage.h +++ b/security/manager/ssl/DataStorage.h @@ -144,10 +144,6 @@ private: static nsresult ValidateKeyAndValue(const nsCString& aKey, const nsCString& aValue); static void TimerCallback(nsITimer* aTimer, void* aClosure); - static PLDHashOperator WriteDataCallback(const nsACString& aKey, Entry aEntry, - void* aArg); - static PLDHashOperator EvictCallback(const nsACString& aKey, Entry aEntry, - void* aArg); void SetTimer(); void ShutdownTimer(); void NotifyObservers(const char* aTopic);