@@ -52,16 +52,16 @@ std::string jsonnet_unparse_number(double v)
52
52
return ss.str ();
53
53
}
54
54
55
+ namespace {
56
+
57
+ static const Fodder EMPTY_FODDER;
58
+
55
59
/* * Maximum parsing depth to avoid stack overflow due to pathological or malicious code.
56
60
* This is especially important when parsing deeply nested structures that could lead to
57
61
* excessive recursion in the parser functions.
58
62
*/
59
63
static const unsigned MAX_PARSER_DEPTH = 1000 ;
60
64
61
- namespace {
62
-
63
- static const Fodder EMPTY_FODDER;
64
-
65
65
static bool op_is_unary (const std::string &op, UnaryOp &uop)
66
66
{
67
67
auto it = unary_map.find (op);
@@ -163,7 +163,7 @@ class Parser {
163
163
* \param current_depth Current recursion depth to prevent stack overflow.
164
164
* \returns The last token (the one that matched parameter end).
165
165
*/
166
- Token parseArgs (ArgParams &args, const std::string &element_kind, bool &got_comma, unsigned current_depth = 0 )
166
+ Token parseArgs (ArgParams &args, const std::string &element_kind, bool &got_comma, unsigned current_depth)
167
167
{
168
168
got_comma = false ;
169
169
bool first = true ;
@@ -214,7 +214,7 @@ class Parser {
214
214
* \param current_depth Current recursion depth to prevent stack overflow.
215
215
* \returns The parameters as ArgParams.
216
216
*/
217
- ArgParams parseParams (const std::string &element_kind, bool &got_comma, Fodder &close_fodder, unsigned current_depth = 0 )
217
+ ArgParams parseParams (const std::string &element_kind, bool &got_comma, Fodder &close_fodder, unsigned current_depth)
218
218
{
219
219
ArgParams params;
220
220
Token paren_r = parseArgs (params, element_kind, got_comma, current_depth);
@@ -244,7 +244,7 @@ class Parser {
244
244
* \param current_depth Current recursion depth to prevent stack overflow.
245
245
* \returns The token after the binding (comma or semicolon).
246
246
*/
247
- Token parseBind (Local::Binds &binds, unsigned current_depth = 0 )
247
+ Token parseBind (Local::Binds &binds, unsigned current_depth)
248
248
{
249
249
Token var_id = popExpect (Token::IDENTIFIER);
250
250
auto *id = alloc->makeIdentifier (var_id.data32 ());
@@ -285,7 +285,7 @@ class Parser {
285
285
* \param current_depth Current recursion depth to prevent stack overflow.
286
286
* \returns The closing brace token.
287
287
*/
288
- Token parseObjectRemainder (AST *&obj, const Token &tok, unsigned current_depth = 0 )
288
+ Token parseObjectRemainder (AST *&obj, const Token &tok, unsigned current_depth)
289
289
{
290
290
if (current_depth >= MAX_PARSER_DEPTH) {
291
291
throw StaticError (peek ().location , " Exceeded maximum parse depth limit." );
@@ -584,7 +584,7 @@ class Parser {
584
584
*/
585
585
Token parseComprehensionSpecs (Token::Kind end, Fodder for_fodder,
586
586
std::vector<ComprehensionSpec> &specs,
587
- unsigned current_depth = 0 )
587
+ unsigned current_depth)
588
588
{
589
589
if (current_depth >= MAX_PARSER_DEPTH) {
590
590
throw StaticError (peek ().location , " Exceeded maximum parse depth limit." );
@@ -623,7 +623,7 @@ class Parser {
623
623
* \param current_depth Current recursion depth to prevent stack overflow.
624
624
* \returns The parsed AST.
625
625
*/
626
- AST *parseTerminalBracketsOrUnary (unsigned current_depth = 0 )
626
+ AST *parseTerminalBracketsOrUnary (unsigned current_depth)
627
627
{
628
628
if (current_depth >= MAX_PARSER_DEPTH) {
629
629
throw StaticError (peek ().location , " Exceeded maximum parse depth limit." );
@@ -807,7 +807,7 @@ class Parser {
807
807
* \param current_depth Current recursion depth to prevent stack overflow.
808
808
* \returns The parsed AST or nullptr.
809
809
*/
810
- AST *maybeParseGreedy (unsigned current_depth = 0 )
810
+ AST *maybeParseGreedy (unsigned current_depth)
811
811
{
812
812
if (current_depth >= MAX_PARSER_DEPTH) {
813
813
throw StaticError (peek ().location , " Exceeded maximum parse depth limit." );
@@ -976,7 +976,7 @@ class Parser {
976
976
* \param current_depth Current recursion depth to prevent stack overflow.
977
977
* \returns The parsed AST.
978
978
*/
979
- AST *parse (unsigned max_precedence, unsigned current_depth = 0 )
979
+ AST *parse (unsigned max_precedence, unsigned current_depth)
980
980
{
981
981
if (current_depth >= MAX_PARSER_DEPTH) {
982
982
throw StaticError (peek ().location , " Exceeded maximum parse depth limit." );
@@ -1005,7 +1005,7 @@ class Parser {
1005
1005
* \param current_depth Current recursion depth to prevent stack overflow.
1006
1006
* \returns The parsed AST.
1007
1007
*/
1008
- AST *parseInfix (AST *lhs, const Token &begin, unsigned max_precedence, unsigned current_depth = 0 )
1008
+ AST *parseInfix (AST *lhs, const Token &begin, unsigned max_precedence, unsigned current_depth)
1009
1009
{
1010
1010
if (current_depth >= MAX_PARSER_DEPTH) {
1011
1011
throw StaticError (peek ().location , " Exceeded maximum parse depth limit." );
0 commit comments