Skip to content

Commit c702247

Browse files
committed
Merge pull request #1157 from carsonmcdonald/maxstack
Add a max stack depth setting
2 parents 040f8ce + e53f613 commit c702247

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

constants.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Sass {
44
namespace Constants {
55

6+
extern const unsigned long MaxCallStack = 1024;
7+
68
// https://github.com/sass/libsass/issues/592
79
// https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
810
// https://github.com/sass/sass/issues/1495#issuecomment-61189114

constants.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
namespace Sass {
55
namespace Constants {
66

7+
// The maximum call stack that can be created
8+
extern const unsigned long MaxCallStack;
9+
710
// https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
811
// The following list of selectors is by increasing specificity:
912
extern const unsigned long Specificity_Star;

eval.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ namespace Sass {
527527

528528
Expression* Eval::operator()(Function_Call* c)
529529
{
530+
if (backtrace->parent != NULL && backtrace->depth() > Constants::MaxCallStack) {
531+
error("Stack depth exceeded max of " + to_string(Constants::MaxCallStack), c->pstate(), backtrace);
532+
}
530533
string name(Util::normalize_underscores(c->name()));
531534
string full_name(name + "[f]");
532535
Arguments* args = c->arguments();

0 commit comments

Comments
 (0)