diff options
author | Carlos Martín Nieto <cmn@elego.de> | 2011-06-28 16:24:51 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-07-05 02:32:17 +0200 |
commit | f58c53ce66cca0b42f615fc6773dbaf4e5fa566f (patch) | |
tree | 8a34e2eedc2aa788671aa14777948a341794fed0 | |
parent | 86b5ab162cbc16aa303a38b85e6c063426568787 (diff) | |
download | libgit2-f58c53ce66cca0b42f615fc6773dbaf4e5fa566f.tar.gz |
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>
-rw-r--r-- | src/config_file.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/config_file.c b/src/config_file.c index 147e8504..044a2431 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -721,11 +721,6 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out) c = line[pos++]; do { - if (cfg->reader.eof){ - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse header. Config file ended unexpectedly"); - goto error; - } - if (isspace(c)){ name[name_length] = '\0'; error = parse_section_header_ext(line, name, section_out); @@ -743,6 +738,9 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out) } 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; free(line); git__strtolower(name); |