mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
Merge branch 'jk/pretty-commit-header-incomplete-line' into maint
By Jeff King * jk/pretty-commit-header-incomplete-line: avoid segfault when reading header of malformed commits
This commit is contained in:
commit
6c227410b5
5
pretty.c
5
pretty.c
@ -439,12 +439,14 @@ static char *get_header(const struct commit *commit, const char *key)
|
||||
int key_len = strlen(key);
|
||||
const char *line = commit->buffer;
|
||||
|
||||
for (;;) {
|
||||
while (line) {
|
||||
const char *eol = strchr(line, '\n'), *next;
|
||||
|
||||
if (line == eol)
|
||||
return NULL;
|
||||
if (!eol) {
|
||||
warning("malformed commit (header is missing newline): %s",
|
||||
sha1_to_hex(commit->object.sha1));
|
||||
eol = line + strlen(line);
|
||||
next = NULL;
|
||||
} else
|
||||
@ -456,6 +458,7 @@ static char *get_header(const struct commit *commit, const char *key)
|
||||
}
|
||||
line = next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *replace_encoding_header(char *buf, const char *encoding)
|
||||
|
Loading…
Reference in New Issue
Block a user