Skip to content

Commit

Permalink
Fix non-keyword subgraph parsing
Browse files Browse the repository at this point in the history
Non-keyword graphs never worked (!). This was uncovered because of
security issue boostorg#364.

parse_subgraph() incorrectly dealt with first_token in the case
where the `subgraph` keyword wasn't used.
  • Loading branch information
sehe committed May 8, 2024
1 parent 8126d97 commit 5007b01
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/read_graphviz_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ namespace read_graphviz_detail

tokenizer(const std::string& str) : begin(str.begin()), end(str.end())
{
std::string end_of_token = "(?=(?:\\W))";
// std::string end_of_token = "(?=(?:\\W))"; // SEHE: unused?
std::string whitespace = "(?:\\s+)";
std::string slash_slash_comment = "(?://.*?$)";
std::string slash_star_comment = "(?:/\\*.*?\\*/)";
Expand Down Expand Up @@ -773,10 +773,18 @@ namespace read_graphviz_detail
bool is_anonymous = true;
if (first_token.type == token::kw_subgraph)
{
if (peek().type == token::identifier)
switch (peek().type)
{
case token::identifier:
name = get().normalized_value;
is_anonymous = false;
break;
case token::left_brace:
is_anonymous = true;
break;
default:
error("Subgraph reference needs a name");
break;
}
}
if (is_anonymous)
Expand All @@ -790,19 +798,19 @@ namespace read_graphviz_detail
= current(); // Initialize properties and defaults
subgraphs[name].members.clear(); // Except member list
}
if (first_token.type == token::kw_subgraph
&& peek().type != token::left_brace)
if (!is_anonymous && peek().type != token::left_brace)
{
if (is_anonymous)
error("Subgraph reference needs a name");
return name;
}
subgraph_name old_sg = current_subgraph_name;
current_subgraph_name = name;
if (peek().type == token::left_brace)
get();
else
error("Wanted left brace to start subgraph");
if (first_token.type != token::left_brace)
{
if (peek().type == token::left_brace)
get();
else
error("Wanted left brace to start subgraph");
}
parse_stmt_list();
if (peek().type == token::right_brace)
get();
Expand Down

0 comments on commit 5007b01

Please sign in to comment.