Commit f58c53ce by Carlos Martín Nieto Committed by Vicent Marti

Correctly detect truncated input in header parsing

If the section header is the last line in the file,
parse_section_header would incorrectly decide that the input had been
truncated.

Fix this by checking whether the actual input line is correctly
formatted.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
parent 86b5ab16
...@@ -721,11 +721,6 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out) ...@@ -721,11 +721,6 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
c = line[pos++]; c = line[pos++];
do { do {
if (cfg->reader.eof){
error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse header. Config file ended unexpectedly");
goto error;
}
if (isspace(c)){ if (isspace(c)){
name[name_length] = '\0'; name[name_length] = '\0';
error = parse_section_header_ext(line, name, section_out); error = parse_section_header_ext(line, name, section_out);
...@@ -743,6 +738,9 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out) ...@@ -743,6 +738,9 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
} while ((c = line[pos++]) != ']'); } while ((c = line[pos++]) != ']');
if (line[pos - 1] != ']')
return git__throw(GIT_EOBJCORRUPTED, "Failed to parse header. Config file ended unexpectedly");
name[name_length] = 0; name[name_length] = 0;
free(line); free(line);
git__strtolower(name); git__strtolower(name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment