Merge branch 'jk/pretty-commit-header-incomplete-line'

Fixes error codepath when a malformed commit object has a header line
chomped in the middle.
This commit is contained in:
Junio C Hamano 2012-05-25 12:05:35 -07:00
commit 407abbabe5

View File

@ -439,12 +439,14 @@ static char *get_header(const struct commit *commit, const char *key)
int key_len = strlen(key); int key_len = strlen(key);
const char *line = commit->buffer; const char *line = commit->buffer;
for (;;) { while (line) {
const char *eol = strchr(line, '\n'), *next; const char *eol = strchr(line, '\n'), *next;
if (line == eol) if (line == eol)
return NULL; return NULL;
if (!eol) { if (!eol) {
warning("malformed commit (header is missing newline): %s",
sha1_to_hex(commit->object.sha1));
eol = line + strlen(line); eol = line + strlen(line);
next = NULL; next = NULL;
} else } else
@ -456,6 +458,7 @@ static char *get_header(const struct commit *commit, const char *key)
} }
line = next; line = next;
} }
return NULL;
} }
static char *replace_encoding_header(char *buf, const char *encoding) static char *replace_encoding_header(char *buf, const char *encoding)