Skip to content

Commit 116b8ec

Browse files
committed
Fix thread-safety for mixin recursions check
1 parent 1fc743c commit 116b8ec

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/expand.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
namespace Sass {
1515

1616
// simple endless recursion protection
17-
const unsigned int maxRecursion = 500;
18-
static unsigned int recursions = 0;
17+
const size_t maxRecursion = 500;
1918

2019
Expand::Expand(Context& ctx, Env* env, Backtrace* bt, std::vector<Selector_List_Obj>* stack)
2120
: ctx(ctx),
2221
eval(Eval(*this)),
22+
recursions(0),
23+
in_keyframes(false),
24+
at_root_without_rule(false),
25+
old_at_root_without_rule(false),
2326
env_stack(std::vector<Env*>()),
2427
block_stack(std::vector<Block_Ptr>()),
2528
call_stack(std::vector<AST_Node_Obj>()),
2629
selector_stack(std::vector<Selector_List_Obj>()),
2730
media_block_stack(std::vector<Media_Block_Ptr>()),
28-
backtrace_stack(std::vector<Backtrace*>()),
29-
in_keyframes(false),
30-
at_root_without_rule(false),
31-
old_at_root_without_rule(false)
31+
backtrace_stack(std::vector<Backtrace*>())
3232
{
3333
env_stack.push_back(0);
3434
env_stack.push_back(env);
@@ -685,12 +685,13 @@ namespace Sass {
685685

686686
Statement_Ptr Expand::operator()(Mixin_Call_Ptr c)
687687
{
688-
recursions ++;
689688

690689
if (recursions > maxRecursion) {
691690
throw Exception::StackError(*c);
692691
}
693692

693+
recursions ++;
694+
694695
Env* env = environment();
695696
std::string full_name(c->name() + "[m]");
696697
if (!env->has(full_name)) {

src/expand.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ namespace Sass {
2626

2727
Context& ctx;
2828
Eval eval;
29+
size_t recursions;
30+
bool in_keyframes;
31+
bool at_root_without_rule;
32+
bool old_at_root_without_rule;
2933

3034
// it's easier to work with vectors
31-
std::vector<Env*> env_stack;
35+
std::vector<Env*> env_stack;
3236
std::vector<Block_Ptr> block_stack;
3337
std::vector<AST_Node_Obj> call_stack;
3438
std::vector<Selector_List_Obj> selector_stack;
3539
std::vector<Media_Block_Ptr> media_block_stack;
36-
std::vector<Backtrace*> backtrace_stack;
37-
bool in_keyframes;
38-
bool at_root_without_rule;
39-
bool old_at_root_without_rule;
40+
std::vector<Backtrace*> backtrace_stack;
4041

4142
Statement_Ptr fallback_impl(AST_Node_Ptr n);
4243

0 commit comments

Comments
 (0)