diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-27 09:03:49 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-27 18:28:43 +0200 |
commit | 8f0b7fa370669f5750d1e3a6d9b26a6fe6eb5655 (patch) | |
tree | ce5706759f70b6d102be3bf0273d117c4c580f70 /Userland/Libraries | |
parent | d053cb6faebe18879e99fd4aea727bee52a03b15 (diff) | |
download | serenity-8f0b7fa370669f5750d1e3a6d9b26a6fe6eb5655.zip |
LibWeb: Verify that a node has styled properties in its styled accessors
For example, it's possible to access Node::computed_values() on a node
that neither has style nor a parent with style. This ultimately results
in a null pointer dereference when we return parent()->computed_values()
as a fallback. This can be a little tricky to track down due to these
functions being inlined, so add an explicit verification.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 1022f2bfc9..f5b69f0d92 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -71,6 +71,7 @@ public: DeprecatedString debug_description() const; bool has_style() const { return m_has_style; } + bool has_style_or_parent_with_style() const; virtual bool can_have_children() const { return true; } @@ -233,8 +234,15 @@ private: template<> inline bool Node::fast_is<NodeWithStyleAndBoxModelMetrics>() const { return is_node_with_style_and_box_model_metrics(); } +inline bool Node::has_style_or_parent_with_style() const +{ + return m_has_style || (parent() != nullptr && parent()->has_style_or_parent_with_style()); +} + inline Gfx::Font const& Node::font() const { + VERIFY(has_style_or_parent_with_style()); + if (m_has_style) return static_cast<NodeWithStyle const*>(this)->font(); return parent()->font(); @@ -247,6 +255,8 @@ inline Gfx::Font const& Node::scaled_font(PaintContext& context) const inline const CSS::ImmutableComputedValues& Node::computed_values() const { + VERIFY(has_style_or_parent_with_style()); + if (m_has_style) return static_cast<NodeWithStyle const*>(this)->computed_values(); return parent()->computed_values(); @@ -254,6 +264,8 @@ inline const CSS::ImmutableComputedValues& Node::computed_values() const inline CSSPixels Node::line_height() const { + VERIFY(has_style_or_parent_with_style()); + if (m_has_style) return static_cast<NodeWithStyle const*>(this)->line_height(); return parent()->line_height(); |