From ef56d81e47c4f6ed601191cab63b3ced9db2080f Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 22 Nov 2018 23:06:27 +0000 Subject: [PATCH] Fix out-of-range string access in special_number Out-of-range string access happened when `s->value()` was shorter than "var(" or "calc(". --- src/fn_colors.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fn_colors.cpp b/src/fn_colors.cpp index 7f501db139..b0142add40 100644 --- a/src/fn_colors.cpp +++ b/src/fn_colors.cpp @@ -10,11 +10,11 @@ namespace Sass { bool special_number(String_Constant_Ptr s) { if (s) { - std::string calc("calc("); - std::string var("var("); - std::string ss(s->value()); - return std::equal(calc.begin(), calc.end(), ss.begin()) || - std::equal(var.begin(), var.end(), ss.begin()); + static const char* const calc = "calc("; + static const char* const var = "var("; + const std::string& str = s->value(); + return str.compare(0, strlen(calc), calc) == 0 || + str.compare(0, strlen(var), var) == 0; } return false; }