Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various edge case crashes #3032

Merged
merged 3 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/extender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ namespace Sass {
// ##########################################################################
bool Extender::checkForUnsatisfiedExtends(Extension& unsatisfied) const
{
if (selectors.empty()) return false;
ExtSmplSelSet originals = getSimpleSelectors();
for (auto target : extensions) {
SimpleSelector* key = target.first;
Expand Down
10 changes: 6 additions & 4 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,15 +2247,17 @@ namespace Sass {
if (lex < kwd_not >()) { media_query->is_negated(true); lex < css_comments >(false); }
else if (lex < kwd_only >()) { media_query->is_restricted(true); lex < css_comments >(false); }

if (lex < identifier_schema >()) media_query->media_type(parse_identifier_schema());
else if (lex < identifier >()) media_query->media_type(parse_interpolated_chunk(lexed));
if (lex < identifier_schema >()) media_query->media_type(parse_identifier_schema());
else if (lex < identifier >()) media_query->media_type(parse_interpolated_chunk(lexed));
else media_query->append(parse_media_expression());

while (lex_css < kwd_and >()) media_query->append(parse_media_expression());
if (lex < identifier_schema >()) {
String_Schema* schema = SASS_MEMORY_NEW(String_Schema, pstate);
schema->append(media_query->media_type());
schema->append(SASS_MEMORY_NEW(String_Constant, pstate, " "));
if (media_query->media_type()) {
schema->append(media_query->media_type());
schema->append(SASS_MEMORY_NEW(String_Constant, pstate, " "));
}
schema->append(parse_identifier_schema());
media_query->media_type(schema);
}
Expand Down
13 changes: 9 additions & 4 deletions src/permutate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Sass {

size_t L = in.size(), n = 0;

if (L == 0) return {};
// Exit early if any entry is empty
for (size_t i = 0; i < L; i += 1) {
if (in[i].size() == 0) return {};
Expand Down Expand Up @@ -80,12 +81,18 @@ namespace Sass {

size_t L = in.size();
size_t n = in.size() - 1;

if (L == 0) return {};
// Exit early if any entry is empty
for (size_t i = 0; i < L; i += 1) {
if (in[i].size() == 0) return {};
}

size_t* state = new size_t[L];
std::vector< std::vector<T>> out;

// First initialize all states for every permutation group
for (size_t i = 0; i < L; i += 1) {
if (in[i].size() == 0) return {};
state[i] = in[i].size() - 1;
}

Expand All @@ -104,10 +111,8 @@ namespace Sass {
// Current group finished
if (state[n] == 0) {
// Find position of next decrement
while (n > 0 && state[--n] == 0)
{
while (n > 0 && state[--n] == 0) {}

}
// Check for end condition
if (state[n] != 0) {
// Decrease next on the left side
Expand Down