mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 894245 part 2 - Reject unknown enum color in CSS parser. r=dholbert
MozReview-Commit-ID: 6jfNESnFde5 --HG-- extra : rebase_source : dbe0b7f1eb45a59ef4df67ba5f1d75da1892cb17
This commit is contained in:
parent
382cf219da
commit
b93e776ac9
5
layout/style/crashtests/894245-1.html
Normal file
5
layout/style/crashtests/894245-1.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<div style="background-color: -moz-mac-defaultbuttontext"></div>
|
||||
<div style="background-color: -moz-mac-focusring"></div>
|
||||
<div style="background-color: -moz-win-communicationstext"></div>
|
||||
<div style="background-color: -moz-gtk-info-bar-text"></div>
|
@ -103,6 +103,7 @@ load 862113.html
|
||||
asserts-if(stylo,5) load 867487.html # bug 1324634
|
||||
load 873222.html
|
||||
asserts-if(stylo,2) load 880862.html # bug 1324701
|
||||
load 894245-1.html
|
||||
load 915440.html
|
||||
load 927734-1.html
|
||||
load 930270-1.html
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/TypedEnumBits.h"
|
||||
@ -51,6 +52,7 @@
|
||||
#include "CSSCalc.h"
|
||||
#include "nsMediaFeatures.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
#include "mozilla/LookAndFeel.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsRuleData.h"
|
||||
#include "mozilla/CSSVariableValues.h"
|
||||
@ -6688,6 +6690,31 @@ CSSParserImpl::ParseDeclarationBlock(uint32_t aFlags, nsCSSContextType aContext)
|
||||
return declaration.forget();
|
||||
}
|
||||
|
||||
static Maybe<int32_t>
|
||||
GetEnumColorValue(nsCSSKeyword aKeyword, bool aIsChrome)
|
||||
{
|
||||
int32_t value;
|
||||
if (!nsCSSProps::FindKeyword(aKeyword, nsCSSProps::kColorKTable, value)) {
|
||||
// Unknown color keyword.
|
||||
return Nothing();
|
||||
}
|
||||
if (value < 0) {
|
||||
// Known special color keyword handled by style system,
|
||||
// e.g. NS_COLOR_CURRENTCOLOR. See nsStyleConsts.h.
|
||||
return Some(value);
|
||||
}
|
||||
nscolor color;
|
||||
auto colorID = static_cast<LookAndFeel::ColorID>(value);
|
||||
if (NS_FAILED(LookAndFeel::GetColor(colorID, !aIsChrome, &color))) {
|
||||
// Known LookAndFeel::ColorID, but this platform's LookAndFeel impl
|
||||
// doesn't map it to a color. (This might be a platform-specific
|
||||
// ColorID, which only makes sense on another platform.)
|
||||
return Nothing();
|
||||
}
|
||||
// Known color provided by LookAndFeel.
|
||||
return Some(value);
|
||||
}
|
||||
|
||||
CSSParseResult
|
||||
CSSParserImpl::ParseColor(nsCSSValue& aValue)
|
||||
{
|
||||
@ -6725,20 +6752,18 @@ CSSParserImpl::ParseColor(nsCSSValue& aValue)
|
||||
}
|
||||
break;
|
||||
|
||||
case eCSSToken_Ident:
|
||||
case eCSSToken_Ident: {
|
||||
if (NS_ColorNameToRGB(tk->mIdent, &rgba)) {
|
||||
aValue.SetStringValue(tk->mIdent, eCSSUnit_Ident);
|
||||
return CSSParseResult::Ok;
|
||||
}
|
||||
else {
|
||||
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
||||
int32_t value;
|
||||
if (nsCSSProps::FindKeyword(keyword, nsCSSProps::kColorKTable, value)) {
|
||||
aValue.SetIntValue(value, eCSSUnit_EnumColor);
|
||||
return CSSParseResult::Ok;
|
||||
}
|
||||
nsCSSKeyword keyword = nsCSSKeywords::LookupKeyword(tk->mIdent);
|
||||
if (Maybe<int32_t> value = GetEnumColorValue(keyword, mIsChrome)) {
|
||||
aValue.SetIntValue(value.value(), eCSSUnit_EnumColor);
|
||||
return CSSParseResult::Ok;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case eCSSToken_Function: {
|
||||
bool isRGB;
|
||||
bool isHSL;
|
||||
|
@ -1044,10 +1044,11 @@ static bool SetColor(const nsCSSValue& aValue, const nscolor aParentColor,
|
||||
LookAndFeel::ColorID colorID = (LookAndFeel::ColorID) intValue;
|
||||
bool useStandinsForNativeColors = aPresContext &&
|
||||
!aPresContext->IsChrome();
|
||||
if (NS_SUCCEEDED(LookAndFeel::GetColor(colorID,
|
||||
useStandinsForNativeColors, &aResult))) {
|
||||
result = true;
|
||||
}
|
||||
DebugOnly<nsresult> rv =
|
||||
LookAndFeel::GetColor(colorID, useStandinsForNativeColors, &aResult);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv),
|
||||
"Unknown enum colors should have been rejected by parser");
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
aResult = NS_RGB(0, 0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user