mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-10 06:56:25 +00:00
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.
This commit is contained in:
parent
ffb1f41949
commit
e39ad747f7
@ -1032,6 +1032,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
first_quote = strchr(line, '"');
|
first_quote = strchr(line, '"');
|
||||||
|
if (first_quote == NULL) {
|
||||||
|
set_parse_error(reader, 0, "Missing quotation marks in section header");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
last_quote = strrchr(line, '"');
|
last_quote = strrchr(line, '"');
|
||||||
quoted_len = last_quote - first_quote;
|
quoted_len = last_quote - first_quote;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user