diff --git a/toolkit/components/url-classifier/src/Makefile.in b/toolkit/components/url-classifier/src/Makefile.in index 1887795cd5b9..8513f8fa7608 100644 --- a/toolkit/components/url-classifier/src/Makefile.in +++ b/toolkit/components/url-classifier/src/Makefile.in @@ -31,6 +31,7 @@ CPPSRCS = \ LOCAL_INCLUDES = \ -I$(srcdir)/../../build \ + $(SQLITE_CFLAGS) \ $(NULL) diff --git a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp index f4541455cae4..6ae7b105afe3 100644 --- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp @@ -77,6 +77,9 @@ #include "prnetdb.h" #include "zlib.h" +// Needed to interpert mozIStorageConnection::GetLastError +#include + /** * The DBServices stores a set of Fragments. A fragment is one URL * fragment containing two or more domain components and some number @@ -3056,6 +3059,11 @@ nsUrlClassifierDBServiceWorker::FinishUpdate() NS_ENSURE_STATE(!mInStream); NS_ENSURE_STATE(mUpdateObserver); + // We need to get the error code before ApplyUpdate, because it might + // close/open the connection. + PRInt32 errcode = SQLITE_OK; + mConnection->GetLastError(&errcode); + ApplyUpdate(); if (NS_SUCCEEDED(mUpdateStatus)) { @@ -3064,7 +3072,13 @@ nsUrlClassifierDBServiceWorker::FinishUpdate() mUpdateObserver->UpdateError(mUpdateStatus); } - if (!mResetRequested) { + // It's important that we only reset the database on an update + // command if the update was successful, otherwise unauthenticated + // updates could cause a database reset. + PRBool resetDB = (NS_SUCCEEDED(mUpdateStatus) && mResetRequested) || + errcode == SQLITE_CORRUPT; + + if (!resetDB) { if (NS_SUCCEEDED(mUpdateStatus)) { PRInt64 now = (PR_Now() / PR_USEC_PER_SEC); for (PRUint32 i = 0; i < mUpdateTables.Length(); i++) { @@ -3079,15 +3093,9 @@ nsUrlClassifierDBServiceWorker::FinishUpdate() } } - // ResetUpdate() clears mResetRequested... - PRBool resetRequested = mResetRequested; - ResetUpdate(); - // It's important that we only reset the database if the update was - // successful, otherwise unauthenticated updates could cause a - // database reset. - if (NS_SUCCEEDED(mUpdateStatus) && resetRequested) { + if (resetDB) { ResetDatabase(); }