-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add smart pointers to CookieStore and CookieJar #28683
Conversation
EWS run on previous version of this PR (hash 8b78e38) |
8b78e38
to
a6d69d7
Compare
EWS run on previous version of this PR (hash a6d69d7) |
@@ -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)); |
There was a problem hiding this comment.
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.
Source/WebCore/loader/CookieJar.cpp
Outdated
frameID = frame->loader().frameID(); | ||
|
||
std::pair<String, bool> result; | ||
if (auto* session = m_storageSessionProvider->storageSession()) | ||
if (WeakPtr session = Ref { m_storageSessionProvider }->storageSession()) |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
Source/WebCore/loader/CookieJar.cpp
Outdated
frameID = frame->loader().frameID(); | ||
|
||
if (auto* session = m_storageSessionProvider->storageSession()) | ||
if (WeakPtr session = Ref { m_storageSessionProvider }->storageSession()) |
There was a problem hiding this comment.
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.
Source/WebCore/loader/CookieJar.cpp
Outdated
frameID = frame->loader().frameID(); | ||
|
||
if (auto* session = m_storageSessionProvider->storageSession()) | ||
if (WeakPtr session = Ref { m_storageSessionProvider }->storageSession()) |
There was a problem hiding this comment.
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.
Source/WebCore/loader/CookieJar.cpp
Outdated
@@ -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(); |
There was a problem hiding this comment.
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.
a6d69d7
to
30aad1f
Compare
EWS run on previous version of this PR (hash 30aad1f) |
class NetworkStorageSession | ||
: public CanMakeWeakPtr<NetworkStorageSession> | ||
, public CanMakeCheckedPtr<NetworkStorageSession> { | ||
WTF_MAKE_NONCOPYABLE(NetworkStorageSession); |
There was a problem hiding this comment.
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.
30aad1f
to
a0d0a7e
Compare
EWS run on current version of this PR (hash a0d0a7e) |
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
to
1963873
Compare
Committed 279064@main (1963873): https://commits.webkit.org/279064@main Reviewed commits have been landed. Closing PR #28683 and removing active labels. |
1963873
a0d0a7e