Skip to content

Configuration parsing: validate section headers with quotes#5073

Merged
ethomson merged 4 commits intomasterfrom
ethomson/config_section_validity
May 22, 2019
Merged

Configuration parsing: validate section headers with quotes#5073
ethomson merged 4 commits intomasterfrom
ethomson/config_section_validity

Conversation

@ethomson
Copy link
Copy Markdown
Member

When parsing configuration section headers, we previously stopped at the first space, and skipped to the first quotation mark. This allows us to support valid section headers like [foo "bar"] or [foo "bar"].

However, by skipping from the end of the section name to the first quotation mark, we ignore any invalid characters there. For example, [foo skipped "bar"] which is not legal.

Validate that there is only whitespace between the end of the section name and the first quotation mark. This also adds additional tests that were useful for my understanding and should help prevent regression.

Fixes #5072

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! One remark, but happy to merge either way as it's not caused by your changes.

Comment thread src/config_parse.c Outdated
if (git__isspace(c)){
name[name_length] = '\0';
result = parse_section_header_ext(reader, line, name, section_out);
result = parse_section_header_ext(reader, line, pos, name, section_out);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like this method name. It's not an extended version of the normal parse_section_header, but instead it parses the subsection-part of section headers (e.g. the quoted part). So I think it should just be called parse_subsection_header or something like that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed.

ethomson added 4 commits May 22, 2019 11:47
Update the configuration parsing error messages to be lower-cased for
consistency with the rest of the library.
When we don't specify a particular column, don't write it in the error
message.  (column "0" is unhelpful.)
When we reach a whitespace after a section name, we assume that what
will follow will be a quoted subsection name.  Pass the current position
of the line being parsed to the subsection parser, so that it can
validate that subsequent characters are additional whitespace or a
single quote.

Previously we would begin parsing after the section name, looking for
the first quotation mark.  This allows invalid characters to embed
themselves between the end of the section name and the first quotation
mark, eg `[section foo "subsection"]`, which is illegal.
The `parse_section_header_ext` name suggests that it as an extended
function for parsing the section header.  It is not.  Rename it to
`parse_subsection_header` to better reflect its true mission.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configuration parsing: Incorrect parsing of section header

2 participants