Skip to content

Commit

Permalink
max_subgraph_nesting_level in read_graphviz_new
Browse files Browse the repository at this point in the history
  • Loading branch information
sehe committed May 2, 2024
1 parent 1f37619 commit 92ee0c4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/read_graphviz_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace boost

namespace read_graphviz_detail
{
static const long max_subgraph_nesting_level = 255;
struct token
{
enum token_type
Expand Down Expand Up @@ -527,6 +528,7 @@ namespace read_graphviz_detail
std::map< subgraph_name, subgraph_info > subgraphs;
std::string current_subgraph_name;
int sgcounter; // Counter for anonymous subgraphs
long sgnesting_level;
std::set< std::pair< node_name, node_name > >
existing_edges; // Used for checking in strict graphs

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

parser(const std::string& gr, parser_result& result)
: the_tokenizer(gr), lookahead(), r(result), sgcounter(0)
: the_tokenizer(gr), lookahead(), r(result), sgcounter(0), sgnesting_level(0)
{
current_subgraph_name = "___root___";
current() = subgraph_info(); // Initialize root graph
Expand Down Expand Up @@ -803,6 +805,10 @@ namespace read_graphviz_detail
return name;
}
subgraph_name old_sg = current_subgraph_name;
if (++sgnesting_level > max_subgraph_nesting_level)
{
error("Exceeded maximum subgraph nesting level");
}
current_subgraph_name = name;
if (first_token.type != token::left_brace)
{
Expand All @@ -817,6 +823,7 @@ namespace read_graphviz_detail
else
error("Wanted right brace to end subgraph");
current_subgraph_name = old_sg;
sgnesting_level -= 1;
return name;
}

Expand Down

0 comments on commit 92ee0c4

Please sign in to comment.