Commit c0ee2ba2 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Allow nullptr in Style[Non]InheritedVariables::SetVariable.

This does not currently cause a crash, entirely because of luck. A value
of nullptr is passed to SetVariable whenever an invalid var()-reference
is used (for example), but it just so happens that needs_resolution_ is
always true in this case, so it short circuits before attempting to de-
reference 'value'.

R=futhark@chromium.org

Bug: 641877
Change-Id: I8b3776a58efb82b5deef74b50561d2ebfd57b817
Reviewed-on: https://chromium-review.googlesource.com/1235725
Commit-Queue: Anders Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593136}
parent e2acbabc
...@@ -362,4 +362,20 @@ TEST_F(CSSVariableResolverTest, RemoveNonInheritedVariable) { ...@@ -362,4 +362,20 @@ TEST_F(CSSVariableResolverTest, RemoveNonInheritedVariable) {
EXPECT_FALSE(non_inherited_variables->RegisteredVariable(name)); EXPECT_FALSE(non_inherited_variables->RegisteredVariable(name));
} }
TEST_F(CSSVariableResolverTest, DontCrashWhenSettingInheritedNullVariable) {
scoped_refptr<StyleInheritedVariables> inherited_variables =
StyleInheritedVariables::Create();
AtomicString name("--test");
inherited_variables->SetVariable(name, nullptr);
inherited_variables->SetRegisteredVariable(name, nullptr);
}
TEST_F(CSSVariableResolverTest, DontCrashWhenSettingNonInheritedNullVariable) {
std::unique_ptr<StyleNonInheritedVariables> inherited_variables =
StyleNonInheritedVariables::Create();
AtomicString name("--test");
inherited_variables->SetVariable(name, nullptr);
inherited_variables->SetRegisteredVariable(name, nullptr);
}
} // namespace blink } // namespace blink
...@@ -33,8 +33,9 @@ class CORE_EXPORT StyleInheritedVariables ...@@ -33,8 +33,9 @@ class CORE_EXPORT StyleInheritedVariables
void SetVariable(const AtomicString& name, void SetVariable(const AtomicString& name,
scoped_refptr<CSSVariableData> value) { scoped_refptr<CSSVariableData> value) {
needs_resolution_ = needs_resolution_ || value->NeedsVariableResolution() || needs_resolution_ =
value->NeedsUrlResolution(); needs_resolution_ || (value && (value->NeedsVariableResolution() ||
value->NeedsUrlResolution()));
data_.Set(name, std::move(value)); data_.Set(name, std::move(value));
} }
CSSVariableData* GetVariable(const AtomicString& name) const; CSSVariableData* GetVariable(const AtomicString& name) const;
......
...@@ -35,8 +35,9 @@ class CORE_EXPORT StyleNonInheritedVariables { ...@@ -35,8 +35,9 @@ class CORE_EXPORT StyleNonInheritedVariables {
void SetVariable(const AtomicString& name, void SetVariable(const AtomicString& name,
scoped_refptr<CSSVariableData> value) { scoped_refptr<CSSVariableData> value) {
needs_resolution_ = needs_resolution_ || value->NeedsVariableResolution() || needs_resolution_ =
value->NeedsUrlResolution(); needs_resolution_ || (value && (value->NeedsVariableResolution() ||
value->NeedsUrlResolution()));
data_.Set(name, std::move(value)); data_.Set(name, std::move(value));
} }
CSSVariableData* GetVariable(const AtomicString& name) const; CSSVariableData* GetVariable(const AtomicString& name) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment