Skip to content

Commit

Permalink
LibWeb/CSS: Remove nullpointer dereference in Parser
Browse files Browse the repository at this point in the history
On platinenmacher.tech there is a document without a window. During
size attribute parsing the window pointer is dereferenced which
causes a crash. This checks for the window to be actually there
before dereferencing.
  • Loading branch information
DasBasti authored and AtkinsSJ committed Jan 9, 2024
1 parent 343d6b0 commit 7d63b8b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6648,7 +6648,8 @@ LengthOrCalculated Parser::Parser::parse_as_sizes_attribute()
// If it does not parse correctly, or it does parse correctly but the <media-condition> evaluates to false, continue.
TokenStream<ComponentValue> token_stream { unparsed_size };
auto media_condition = parse_media_condition(token_stream, MediaCondition::AllowOr::Yes);
if (media_condition && media_condition->evaluate(*m_context.window()) == MatchResult::True) {
auto context_window = m_context.window();
if (context_window && media_condition && media_condition->evaluate(*context_window) == MatchResult::True) {
return size.value();
} else {
continue;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ AK::URL ParsingContext::complete_url(StringView relative_url) const

HTML::Window const* ParsingContext::window() const
{
return m_document ? &m_document->window() : nullptr;
return m_document && m_document->default_view() ? &m_document->window() : nullptr;
}

}

0 comments on commit 7d63b8b

Please sign in to comment.