Skip to content

Commit 95b80a9

Browse files
committed
max_subgraph_nesting_level in read_graphviz_new
1 parent 82f623f commit 95b80a9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: src/read_graphviz_new.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace boost
5353

5454
namespace read_graphviz_detail
5555
{
56+
static const long max_subgraph_nesting_level = 255;
5657
struct token
5758
{
5859
enum token_type
@@ -527,6 +528,7 @@ namespace read_graphviz_detail
527528
std::map< subgraph_name, subgraph_info > subgraphs;
528529
std::string current_subgraph_name;
529530
int sgcounter; // Counter for anonymous subgraphs
531+
long sgnesting_level;
530532
std::set< std::pair< node_name, node_name > >
531533
existing_edges; // Used for checking in strict graphs
532534

@@ -538,7 +540,7 @@ namespace read_graphviz_detail
538540
subgraph_member_list& current_members() { return current().members; }
539541

540542
parser(const std::string& gr, parser_result& result)
541-
: the_tokenizer(gr), lookahead(), r(result), sgcounter(0)
543+
: the_tokenizer(gr), lookahead(), r(result), sgcounter(0), sgnesting_level(0)
542544
{
543545
current_subgraph_name = "___root___";
544546
current() = subgraph_info(); // Initialize root graph
@@ -803,6 +805,10 @@ namespace read_graphviz_detail
803805
return name;
804806
}
805807
subgraph_name old_sg = current_subgraph_name;
808+
if (++sgnesting_level > max_subgraph_nesting_level)
809+
{
810+
error("Exceeded maximum subgraph nesting level");
811+
}
806812
current_subgraph_name = name;
807813
if (first_token.type != token::left_brace)
808814
{
@@ -817,6 +823,7 @@ namespace read_graphviz_detail
817823
else
818824
error("Wanted right brace to end subgraph");
819825
current_subgraph_name = old_sg;
826+
sgnesting_level -= 1;
820827
return name;
821828
}
822829

0 commit comments

Comments
 (0)