Bug 210683

Summary: [IPC hardening] Use MESSAGE_CHECK in WebPageProxy::loadRecentSearches() and WebPageProxy::saveRecentSearches()
Product: WebKit Reporter: David Kilzer (:ddkilzer) <ddkilzer>
Component: WebKit2Assignee: David Kilzer (:ddkilzer) <ddkilzer>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, cdumez, ggaren, useafterfree, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch v1 none

Description David Kilzer (:ddkilzer) 2020-04-17 21:02:48 PDT
Use MESSAGE_CHECK in WebPageProxy::loadRecentSearches() and WebPageProxy::saveRecentSearches().

<rdar://problem/59240446>
Comment 1 David Kilzer (:ddkilzer) 2020-04-17 21:07:44 PDT
Created attachment 396830 [details]
Patch v1
Comment 2 David Kilzer (:ddkilzer) 2020-04-18 09:20:10 PDT
Comment on attachment 396830 [details]
Patch v1

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

> Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:73
> -    if (!name) {
> -        // FIXME: This should be a message check.
> -        return;
> -    }
> +    MESSAGE_CHECK(!name.isNull());

We could also write this like so:

    MESSAGE_CHECK(!!name);

I'm not sure if that is easier to read that !name.isNull().
Comment 3 Geoffrey Garen 2020-04-19 12:15:03 PDT
Comment on attachment 396830 [details]
Patch v1

r=me

My preference is the "!name.isNull()" style. I think it reads more clearly. Also, "!!" is kind of mind-bending if you haven't seen it before.

I believe that the "!!" style originated, especially on Windows, to work around a missing feature in C++ (a safe way to convert to boolean without converting to integer by accident). You can see vestigial remnants of the same issue in WebKit's uses of "UnspecifiedBoolType" (which is even more mind-bending). See also http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2333.html. In the modern C++ world, where operator bool can be made explicit, I believe there is no need to use "!!" anymore.
Comment 4 EWS 2020-04-19 19:18:38 PDT
Committed r260347: <https://trac.webkit.org/changeset/260347>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396830 [details].