[macOS] Avoid crashing the UI process when writing empty data to the pasteboard
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 May 2019 14:39:10 +0000 (14:39 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 May 2019 14:39:10 +0000 (14:39 +0000)
commit09fc8515517335d54750d3c51c8ef1950c760034
treec08452cebe743ce99409d78fc8c43038e8ed7ee7
parent404b205620c0085ec501d4ac85b621cd6a3a5047
[macOS] Avoid crashing the UI process when writing empty data to the pasteboard
https://bugs.webkit.org/show_bug.cgi?id=197644
<rdar://problem/50526364>

Reviewed by Tim Horton.

Source/WebKit:

Test: WebKit.WKWebProcessPlugInDoNotCrashWhenCopyingEmptyClientData

* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::setBufferForType):

Make this function robust by not attempting to create a shared memory buffer in the case where the given data
buffer is empty.

Tools:

Add a new API test to exercise a possible scenario where we may crash while writing data to the pasteboard.

* TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegate.mm:
* TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegatePlugIn.mm:
(-[BundleEditingDelegatePlugIn webProcessPlugIn:didCreateBrowserContextController:]):
(-[BundleEditingDelegatePlugIn _webProcessPlugInBrowserContextController:pasteboardDataForRange:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245009 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegate.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/BundleEditingDelegatePlugIn.mm