Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e126bc9

Browse files
committed
config_file: handle missing quotation marks in section header
When parsing a section header we expect something along the format of '[section "subsection"]'. When a section is mal-formated and is entirely missing its quotation marks we catch this case by observing that `strchr(line, '"') - strrchr(line, '"') = NULL - NULL = 0` and error out. Unfortunately, the error message is misleading though, as we state that we are missing the closing quotation mark while we in fact miss both quotation marks. Improve the error message by explicitly checking if the first quotation mark could be found and, if not, stating that quotation marks are completely missing.
1 parent 345758a commit e126bc9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/config_file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10321032
*/
10331033

10341034
first_quote = strchr(line, '"');
1035+
if (first_quote == NULL) {
1036+
set_parse_error(reader, 0, "Missing quotation marks in section header");
1037+
return -1;
1038+
}
1039+
10351040
last_quote = strrchr(line, '"');
10361041
quoted_len = last_quote - first_quote;
10371042

0 commit comments

Comments
 (0)