Skip to content

Commit

Permalink
Merge branch 'jk/pretty-commit-header-incomplete-line' into maint
Browse files Browse the repository at this point in the history
By Jeff King
* jk/pretty-commit-header-incomplete-line:
  avoid segfault when reading header of malformed commits
  • Loading branch information
Junio C Hamano committed Jun 1, 2012
2 parents 92ddfaa + a9c7a8a commit 6c22741
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6c22741

Please sign in to comment.