Changeset 252817 in webkit


Ignore:
Timestamp:
Nov 22, 2019 4:42:28 PM (4 years ago)
Author:
Kate Cheney
Message:

ITP Database crashes if table schema is not correct
https://bugs.webkit.org/show_bug.cgi?id=204458
<rdar://problem/57399084>

Reviewed by Brent Fulgham.

ITP database was crashing if the table schema wasn't correct. This
should instead be handled by re-opening a new database with a correct
schema to allow for future schema updates.

  • NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:

(WebKit::ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema):
(WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary):

  • NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r252812 r252817  
     12019-11-22  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        ITP Database crashes if table schema is not correct
     4        https://bugs.webkit.org/show_bug.cgi?id=204458
     5        <rdar://problem/57399084>
     6       
     7        Reviewed by Brent Fulgham.
     8
     9        ITP database was crashing if the table schema wasn't correct. This
     10        should instead be handled by re-opening a new database with a correct
     11        schema to allow for future schema updates.
     12
     13        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
     14        (WebKit::ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema):
     15        (WebKit::ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary):
     16        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h:
     17
    1182019-11-22  Chris Dumez  <cdumez@apple.com>
    219
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp

    r252641 r252817  
    122122constexpr auto getResourceDataByDomainNameQuery = "SELECT * FROM ObservedDomains WHERE registrableDomain = ?";
    123123constexpr auto getAllDomainsQuery = "SELECT registrableDomain FROM ObservedDomains"_s;
     124
     125const char* tables[] = {
     126    "ObservedDomains",
     127    "TopLevelDomains",
     128    "StorageAccessUnderTopFrameDomains",
     129    "TopFrameUniqueRedirectsTo",
     130    "TopFrameUniqueRedirectsFrom",
     131    "TopFrameLinkDecorationsFrom",
     132    "TopFrameLoadedThirdPartyScripts",
     133    "SubframeUnderTopFrameDomains",
     134    "SubresourceUnderTopFrameDomains",
     135    "SubresourceUniqueRedirectsTo",
     136    "SubresourceUniqueRedirectsFrom"
     137};
    124138
    125139// CREATE TABLE Queries
     
    289303}
    290304
     305static void resetStatement(SQLiteStatement& statement)
     306{
     307    int resetResult = statement.reset();
     308    ASSERT_UNUSED(resetResult, resetResult == SQLITE_OK);
     309}
     310
     311bool ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema()
     312{
     313    SQLiteStatement statement(m_database, "SELECT 1 from sqlite_master WHERE type='table' and tbl_name=?");
     314    if (statement.prepare() != SQLITE_OK) {
     315        RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema failed to prepare, error message: %{public}s", this, m_database.lastErrorMsg());
     316        return false;
     317    }
     318
     319    bool hasAllTables = true;
     320    for (auto table : tables) {
     321        if (statement.bindText(1, table) != SQLITE_OK) {
     322            RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema failed to bind, error message: %{public}s", this, m_database.lastErrorMsg());
     323            return false;
     324        }
     325        if (statement.step() != SQLITE_ROW) {
     326            RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::isCorrectTableSchema schema is missing table: %s", this, table);
     327            hasAllTables = false;
     328        }
     329        resetStatement(statement);
     330    }
     331    return hasAllTables;
     332}
     333
    291334void ResourceLoadStatisticsDatabaseStore::openAndDropOldDatabaseIfNecessary()
    292335{
    293336    openITPDatabase();
     337
     338    if (!isCorrectTableSchema()) {
     339        m_database.close();
     340        // FIXME: Migrate existing data to new database file instead of deleting it (204482).
     341        FileSystem::deleteFile(m_storageDirectoryPath);
     342        openITPDatabase();
     343        return;
     344    }
    294345
    295346    String currentSchema;
     
    323374        openITPDatabase();
    324375    }
    325 }
    326 
    327 static void resetStatement(SQLiteStatement& statement)
    328 {
    329     int resetResult = statement.reset();
    330     ASSERT_UNUSED(resetResult, resetResult == SQLITE_OK);
    331376}
    332377
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h

    r252641 r252817  
    137137private:
    138138    void openITPDatabase();
     139    bool isCorrectTableSchema();
    139140    void openAndDropOldDatabaseIfNecessary();
    140141    String getDomainStringFromDomainID(unsigned) const;
Note: See TracChangeset for help on using the changeset viewer.