fix: RenderFrameHost nullptr dereference (#45508)

* fix: add nullptr tests before using render_frame_

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: extract-method HasRenderFrame()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-02-07 10:03:01 +01:00 committed by GitHub
parent cb7eb6fe3d
commit 984b8f9b1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -101,8 +101,14 @@ class WebFrameMain final : public gin::Wrappable<WebFrameMain>,
void TeardownMojoConnection();
void OnRendererConnectionError();
// WebFrameMain can outlive its RenderFrameHost pointer so we need to check
// whether its been disposed of prior to accessing it.
[[nodiscard]] constexpr bool HasRenderFrame() const {
return !render_frame_disposed_ && render_frame_ != nullptr;
}
// Throws a JS error if HasRenderFrame() is false.
// WebFrameMain can outlive its RenderFrameHost pointer,
// so we need to check whether its been disposed of
// prior to accessing it.
bool CheckRenderFrame() const;
v8::Local<v8::Promise> ExecuteJavaScript(gin::Arguments* args,