Bug 185873 - [Curl] Not all Cookie database files are deleted on corruption
Summary: [Curl] Not all Cookie database files are deleted on corruption
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-05-22 10:40 PDT by Christopher Reid
Modified: 2018-08-16 10:41 PDT (History)
9 users (show)

See Also:


Attachments
Patch (4.98 KB, patch)
2018-05-22 12:44 PDT, Christopher Reid
Hironori.Fujii: review-
ews: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews200 for win-future (12.79 MB, application/zip)
2018-05-22 14:50 PDT, Build Bot
no flags Details
Updated patch (6.67 KB, patch)
2018-08-16 00:08 PDT, Christopher Reid
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Reid 2018-05-22 10:40:26 PDT
cookie.jar.db and cookie.jar.db-corrupted are not getting deleted when database corruption is detected.
Comment 1 Christopher Reid 2018-05-22 12:44:19 PDT
Created attachment 341007 [details]
Patch
Comment 2 Build Bot 2018-05-22 14:50:18 PDT
Comment on attachment 341007 [details]
Patch

Attachment 341007 [details] did not pass win-ews (win):
Output: http://webkit-queues.webkit.org/results/7768844

New failing tests:
http/tests/security/video-poster-cross-origin-crash2.html
Comment 3 Build Bot 2018-05-22 14:50:30 PDT
Created attachment 341032 [details]
Archive of layout-test-results from ews200 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: ews200  Port: win-future  Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Comment 4 Fujii Hironori 2018-07-17 22:26:25 PDT
Comment on attachment 341007 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=341007&action=review

> Source/WebCore/platform/network/curl/CookieJarDB.cpp:222
> +        return true;

Should this be a following code?
if (resultCode != SQLITE_OK)
    return false;

> Source/WebCore/platform/network/curl/CookieJarDB.cpp:249
> +    FileSystem::deleteFile(m_databasePath + "-shm");

Why do you need to do 'deleteFile(m_databasePath + "-shm")' twice?

> Source/WebCore/platform/network/curl/CookieJarDB.cpp:510
> +

You use checkSQLiteReturnCode in ASSERT macro even though it has a side effect.
The side effect is effective only in Debug build.
Is this intentional?

checkSQLiteReturnCode should be defined as:

void CookieJarDB::checkSQLiteReturnCode(int actual)
{
    if (!m_detectedDatabaseCorruption) {
        switch (actual) {
        case SQLITE_CORRUPT:
        case SQLITE_SCHEMA:
        case SQLITE_FORMAT:
        case SQLITE_NOTADB:
            flagDatabaseCorruption();
            m_detectedDatabaseCorruption = true;
        }
    }
}

This code should be replaced with:

checkSQLiteReturnCode(ret);
if (ret != SQLITE_OK && ret != SQLITE_DONE && ret != SQLITE_ROW && !ignoreError)
    LOG_ERROR("Failed to execute %s error: %s", sql, m_database.lastErrorMsg());

Other ASSERT(checkSQLiteReturnCode(ret, SQLITE_DONE)) should be replaced with a following code:

checkSQLiteReturnCode(ret);
ASSERT(ret == SQLITE_DONE);
Comment 5 Fujii Hironori 2018-07-17 23:09:20 PDT
Comment on attachment 341007 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=341007&action=review

> Source/WebCore/platform/network/curl/CookieJarDB.cpp:236
> +    return false;

Inverse the condition for the consistency.

if (resultText != "ok") {
    LOG_ERROR("Cookie database integrity check failed - %s", resultText.ascii().data());
    return false;
}

return true;
Comment 6 Christopher Reid 2018-08-16 00:08:50 PDT
Created attachment 347252 [details]
Updated patch
Comment 7 Christopher Reid 2018-08-16 00:11:54 PDT
(In reply to Fujii Hironori from comment #4)
> Comment on attachment 341007 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=341007&action=review
> 
> > Source/WebCore/platform/network/curl/CookieJarDB.cpp:222
> > +        return true;
> 
> Should this be a following code?
> if (resultCode != SQLITE_OK)
>     return false;
> 

Yeah, step also shouldn't even be returning SQLITE_OK.

> > Source/WebCore/platform/network/curl/CookieJarDB.cpp:249
> > +    FileSystem::deleteFile(m_databasePath + "-shm");
> 
> Why do you need to do 'deleteFile(m_databasePath + "-shm")' twice?
> 

Right, that shouldn't have been added.

> > Source/WebCore/platform/network/curl/CookieJarDB.cpp:510
> > +
> 
> You use checkSQLiteReturnCode in ASSERT macro even though it has a side
> effect.
> The side effect is effective only in Debug build.
> Is this intentional?
> 
> checkSQLiteReturnCode should be defined as:
> 
> void CookieJarDB::checkSQLiteReturnCode(int actual)
> {
>     if (!m_detectedDatabaseCorruption) {
>         switch (actual) {
>         case SQLITE_CORRUPT:
>         case SQLITE_SCHEMA:
>         case SQLITE_FORMAT:
>         case SQLITE_NOTADB:
>             flagDatabaseCorruption();
>             m_detectedDatabaseCorruption = true;
>         }
>     }
> }
> 
> This code should be replaced with:
> 
> checkSQLiteReturnCode(ret);
> if (ret != SQLITE_OK && ret != SQLITE_DONE && ret != SQLITE_ROW &&
> !ignoreError)
>     LOG_ERROR("Failed to execute %s error: %s", sql,
> m_database.lastErrorMsg());
> 
> Other ASSERT(checkSQLiteReturnCode(ret, SQLITE_DONE)) should be replaced
> with a following code:
> 
> checkSQLiteReturnCode(ret);
> ASSERT(ret == SQLITE_DONE);

That looks much better.
Comment 8 WebKit Commit Bot 2018-08-16 10:40:41 PDT
Comment on attachment 347252 [details]
Updated patch

Clearing flags on attachment: 347252

Committed r234938: <https://trac.webkit.org/changeset/234938>
Comment 9 WebKit Commit Bot 2018-08-16 10:40:43 PDT
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2018-08-16 10:41:33 PDT
<rdar://problem/43387503>