Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smart pointers to CookieStore and CookieJar #28683

Conversation

abigailfox
Copy link
Contributor

@abigailfox abigailfox commented May 16, 2024

1963873

Add smart pointers to CookieStore and CookieJar
https://bugs.webkit.org/show_bug.cgi?id=274285
rdar://128231784

Reviewed by Chris Dumez and Ryosuke Niwa.

* Source/WebCore/Modules/cookie-store/CookieStore.cpp:
(WebCore::CookieStore::MainThreadBridge::ensureOnMainThread):
(WebCore::CookieStore::MainThreadBridge::get):
(WebCore::CookieStore::get):
(WebCore::CookieStore::getAll):
(WebCore::CookieStore::set):
(WebCore::CookieStore::eventListenersDidChange):
* Source/WebCore/loader/CookieJar.cpp:
(WebCore::CookieJar::cookies const):
(WebCore::CookieJar::cookieRequestHeaderFieldProxy):
(WebCore::CookieJar::setCookies):
(WebCore::CookieJar::cookiesEnabled):
(WebCore::CookieJar::cookieRequestHeaderFieldValue const):
(WebCore::CookieJar::getRawCookies const):
(WebCore::CookieJar::setRawCookie):
(WebCore::CookieJar::deleteCookie):

Canonical link: https://commits.webkit.org/279064@main

a0d0a7e

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ§ͺ wpe-wk2 βœ… πŸ§ͺ wincairo-tests
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
βœ… πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-cairo
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-wk2-stress ❌ πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@abigailfox abigailfox requested a review from cdumez as a code owner May 16, 2024 22:55
@abigailfox abigailfox self-assigned this May 16, 2024
@abigailfox abigailfox added the WebCore Misc. For miscellaneous bugs in the WebCore framework (and not JavaScriptCore or WebKit). label May 16, 2024
@abigailfox abigailfox marked this pull request as draft May 17, 2024 01:19
@abigailfox abigailfox force-pushed the eng/Add-smart-pointers-to-CookieStore-and-CookieJar branch from 8b78e38 to a6d69d7 Compare May 17, 2024 01:47
@abigailfox abigailfox marked this pull request as ready for review May 17, 2024 01:49
@abigailfox abigailfox requested review from ddkilzer and rniwa May 17, 2024 01:50
@@ -272,7 +272,7 @@ void CookieStore::get(CookieStoreGetOptions&& options, Ref<DeferredPromise>&& pr
promise->resolve<IDLDictionary<CookieListItem>>(CookieListItem(WTFMove(cookies[0])));
};

m_mainThreadBridge->get(WTFMove(options), WTFMove(completionHandler));
Ref { m_mainThreadBridge }->get(WTFMove(options), WTFMove(completionHandler));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a protectedMainBridge() function that returns a Ref, since this is done several times.

frameID = frame->loader().frameID();

std::pair<String, bool> result;
if (auto* session = m_storageSessionProvider->storageSession())
if (WeakPtr session = Ref { m_storageSessionProvider }->storageSession())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a protectedStorageSessionProvider() since this is done several times.

@@ -272,7 +272,7 @@ void CookieStore::get(CookieStoreGetOptions&& options, Ref<DeferredPromise>&& pr
promise->resolve<IDLDictionary<CookieListItem>>(CookieListItem(WTFMove(cookies[0])));
};

m_mainThreadBridge->get(WTFMove(options), WTFMove(completionHandler));
Ref { m_mainThreadBridge }->get(WTFMove(options), WTFMove(completionHandler));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than keep repeating Ref { m_mainThreadBridge }, we should add protectedMainThreadBridge function which returns a Ref.

@@ -98,7 +98,7 @@ void CookieStore::MainThreadBridge::ensureOnMainThread(Function<void(ScriptExecu
{
ASSERT(m_cookieStore);

RefPtr context = m_cookieStore->scriptExecutionContext();
RefPtr context = RefPtr { m_cookieStore.get() }->scriptExecutionContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the preferred convention is to add protectedCookieStore which returns a Ref and call that here.

frameID = frame->loader().frameID();

if (auto* session = m_storageSessionProvider->storageSession())
if (WeakPtr session = Ref { m_storageSessionProvider }->storageSession())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for adding protectedStorageSessionProvider() instead.

frameID = frame->loader().frameID();

if (auto* session = m_storageSessionProvider->storageSession())
if (WeakPtr session = Ref { m_storageSessionProvider }->storageSession())
Copy link
Member

@rniwa rniwa May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make NetworkStorageSession inherit from CanMakeCheckedPtr and use a CheckedPtr here instead. WeakPtr doesn't prevent UAF here because even if WeakPtr was not null at the time of if condition evaluation, it can become null later underneath us. CheckedPtr will prevent UAF in that case.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label May 17, 2024
@@ -123,10 +123,10 @@ void CookieJar::setCookies(Document& document, const URL& url, const String& coo
{
auto pageID = document.pageID();
std::optional<FrameIdentifier> frameID;
if (auto* frame = document.frame())
if (RefPtr frame = document.frame())
frameID = frame->loader().frameID();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't these just be frameID = frame->frameID();? Then we wouldn't need the smart pointer.

@abigailfox abigailfox removed the merging-blocked Applied to prevent a change from being merged label May 18, 2024
@abigailfox abigailfox force-pushed the eng/Add-smart-pointers-to-CookieStore-and-CookieJar branch from a6d69d7 to 30aad1f Compare May 18, 2024 03:14
class NetworkStorageSession
: public CanMakeWeakPtr<NetworkStorageSession>
, public CanMakeCheckedPtr<NetworkStorageSession> {
WTF_MAKE_NONCOPYABLE(NetworkStorageSession);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think we normally extra indent macros like this.

@abigailfox abigailfox force-pushed the eng/Add-smart-pointers-to-CookieStore-and-CookieJar branch from 30aad1f to a0d0a7e Compare May 20, 2024 17:20
@abigailfox abigailfox added the merge-queue Applied to send a pull request to merge-queue label May 21, 2024
https://bugs.webkit.org/show_bug.cgi?id=274285
rdar://128231784

Reviewed by Chris Dumez and Ryosuke Niwa.

* Source/WebCore/Modules/cookie-store/CookieStore.cpp:
(WebCore::CookieStore::MainThreadBridge::ensureOnMainThread):
(WebCore::CookieStore::MainThreadBridge::get):
(WebCore::CookieStore::get):
(WebCore::CookieStore::getAll):
(WebCore::CookieStore::set):
(WebCore::CookieStore::eventListenersDidChange):
* Source/WebCore/loader/CookieJar.cpp:
(WebCore::CookieJar::cookies const):
(WebCore::CookieJar::cookieRequestHeaderFieldProxy):
(WebCore::CookieJar::setCookies):
(WebCore::CookieJar::cookiesEnabled):
(WebCore::CookieJar::cookieRequestHeaderFieldValue const):
(WebCore::CookieJar::getRawCookies const):
(WebCore::CookieJar::setRawCookie):
(WebCore::CookieJar::deleteCookie):

Canonical link: https://commits.webkit.org/279064@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Add-smart-pointers-to-CookieStore-and-CookieJar branch from a0d0a7e to 1963873 Compare May 21, 2024 17:42
@webkit-commit-queue
Copy link
Collaborator

Committed 279064@main (1963873): https://commits.webkit.org/279064@main

Reviewed commits have been landed. Closing PR #28683 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 21, 2024
@webkit-commit-queue webkit-commit-queue merged commit 1963873 into WebKit:main May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebCore Misc. For miscellaneous bugs in the WebCore framework (and not JavaScriptCore or WebKit).
Projects
None yet
7 participants