From 994695c669085058c4a500f295a0531893eff77a Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Sun, 3 Nov 2019 00:42:10 +0100 Subject: [PATCH] Fix out of boundary vector access Fixes https://github.com/sass/libsass/issues/3001 --- src/parser_selectors.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/parser_selectors.cpp b/src/parser_selectors.cpp index d76dd2ca7..3b4a6e2d9 100644 --- a/src/parser_selectors.cpp +++ b/src/parser_selectors.cpp @@ -140,10 +140,12 @@ namespace Sass { // parent selector only allowed at start // upcoming Sass may allow also trailing ParserState state(pstate); - SimpleSelectorObj prev = (*seq)[seq->length()-1]; - std::string sel(prev->to_string({ NESTED, 5 })); std::string found("&"); - if (lex < identifier >()) { found += std::string(lexed); } + if (lex < identifier >()) { + found += std::string(lexed); + } + std::string sel(seq->hasRealParent() ? "&" : ""); + if (!seq->empty()) { sel = seq->last()->to_string({ NESTED, 5 }); } // ToDo: parser should throw parser exceptions error("Invalid CSS after \"" + sel + "\": expected \"{\", was \"" + found + "\"\n\n" "\"" + found + "\" may only be used at the beginning of a compound selector.", state);