Skip to content

Commit 5801404

Browse files
glebmxzyfer
authored andcommitted
Fix out-of-range string access in special_number
Out-of-range string access happened when `s->value()` was shorter than "var(" or "calc(".
1 parent 534065c commit 5801404

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/fn_colors.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace Sass {
1010

1111
bool special_number(String_Constant_Ptr s) {
1212
if (s) {
13-
std::string calc("calc(");
14-
std::string var("var(");
15-
std::string ss(s->value());
16-
return std::equal(calc.begin(), calc.end(), ss.begin()) ||
17-
std::equal(var.begin(), var.end(), ss.begin());
13+
static const char* const calc = "calc(";
14+
static const char* const var = "var(";
15+
const std::string& str = s->value();
16+
return str.compare(0, strlen(calc), calc) == 0 ||
17+
str.compare(0, strlen(var), var) == 0;
1818
}
1919
return false;
2020
}

0 commit comments

Comments
 (0)