Bug 180590 - Web Inspector: CRASH at InspectorConsoleAgent::enable when iterating mutable list of buffered console messages
Summary: Web Inspector: CRASH at InspectorConsoleAgent::enable when iterating mutable ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-12-08 11:23 PST by Joseph Pecoraro
Modified: 2017-12-08 21:12 PST (History)
11 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (1.76 KB, patch)
2017-12-08 11:24 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2017-12-08 11:23:37 PST
CRASH at InspectorConsoleAgent::enable when iterating mutable list of buffered console messages

> void InspectorConsoleAgent::enable()
> {
>     ...
>     size_t messageCount = m_consoleMessages.size();
>     for (size_t i = 0; i < messageCount; ++i)
>         m_consoleMessages[i]->addToFrontend(*m_frontendDispatcher, m_injectedScriptManager, false);
> }

Saw a crash in the debugger at this point:

  * Original messagesCount was 96
  * i was 93 and the m_consoleMessages.size() was 93

This is likely only possible if when logging a console message causes another console message to happen, but we shouldn't iterate a list that can mutate (m_consoleMessages).
Comment 1 Joseph Pecoraro 2017-12-08 11:23:47 PST
<rdar://problem/35882767>
Comment 2 Joseph Pecoraro 2017-12-08 11:24:53 PST
Created attachment 328839 [details]
[PATCH] Proposed Fix
Comment 3 Mark Lam 2017-12-08 11:28:47 PST
Comment on attachment 328839 [details]
[PATCH] Proposed Fix

r=me
Comment 4 WebKit Commit Bot 2017-12-08 12:21:31 PST
Comment on attachment 328839 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 328839

Committed r225693: <https://trac.webkit.org/changeset/225693>
Comment 5 WebKit Commit Bot 2017-12-08 12:21:32 PST
All reviewed patches have been landed.  Closing bug.
Comment 6 Darin Adler 2017-12-08 21:12:12 PST
Comment on attachment 328839 [details]
[PATCH] Proposed Fix

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

> Source/JavaScriptCore/inspector/agents/InspectorConsoleAgent.cpp:90
> +    Vector<std::unique_ptr<ConsoleMessage>> messages;
> +    m_consoleMessages.swap(messages);
> +
> +    for (size_t i = 0; i < messages.size(); ++i)
> +        messages[i]->addToFrontend(*m_frontendDispatcher, m_injectedScriptManager, false);

The above is how we used to write code like this before we had move semantics. Now we can do better:

    auto messages = WTFMove(m_consoleMessage);
    for (auto message : messages)
        message->addToFrontend(*m_frontendDispatcher, m_injectedScriptManager, false);