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 thread-safety for mixin recursions check #2286

Merged
merged 1 commit into from
Jan 5, 2017
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
15 changes: 8 additions & 7 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
namespace Sass {

// simple endless recursion protection
const unsigned int maxRecursion = 500;
static unsigned int recursions = 0;
const size_t maxRecursion = 500;

Expand::Expand(Context& ctx, Env* env, Backtrace* bt, std::vector<Selector_List_Obj>* stack)
: ctx(ctx),
eval(Eval(*this)),
recursions(0),
in_keyframes(false),
at_root_without_rule(false),
old_at_root_without_rule(false),
env_stack(std::vector<Env*>()),
block_stack(std::vector<Block_Ptr>()),
call_stack(std::vector<AST_Node_Obj>()),
selector_stack(std::vector<Selector_List_Obj>()),
media_block_stack(std::vector<Media_Block_Ptr>()),
backtrace_stack(std::vector<Backtrace*>()),
in_keyframes(false),
at_root_without_rule(false),
old_at_root_without_rule(false)
backtrace_stack(std::vector<Backtrace*>())
{
env_stack.push_back(0);
env_stack.push_back(env);
Expand Down Expand Up @@ -685,12 +685,13 @@ namespace Sass {

Statement_Ptr Expand::operator()(Mixin_Call_Ptr c)
{
recursions ++;

if (recursions > maxRecursion) {
throw Exception::StackError(*c);
}

recursions ++;

Env* env = environment();
std::string full_name(c->name() + "[m]");
if (!env->has(full_name)) {
Expand Down
11 changes: 6 additions & 5 deletions src/expand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ namespace Sass {

Context& ctx;
Eval eval;
size_t recursions;
bool in_keyframes;
bool at_root_without_rule;
bool old_at_root_without_rule;

// it's easier to work with vectors
std::vector<Env*> env_stack;
std::vector<Env*> env_stack;
std::vector<Block_Ptr> block_stack;
std::vector<AST_Node_Obj> call_stack;
std::vector<Selector_List_Obj> selector_stack;
std::vector<Media_Block_Ptr> media_block_stack;
std::vector<Backtrace*> backtrace_stack;
bool in_keyframes;
bool at_root_without_rule;
bool old_at_root_without_rule;
std::vector<Backtrace*> backtrace_stack;

Statement_Ptr fallback_impl(AST_Node_Ptr n);

Expand Down