Merge branch 'jk/pretty-commit-header-incomplete-line'
authorJunio C Hamano <gitster@pobox.com>
Fri, 25 May 2012 19:05:35 +0000 (12:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 May 2012 19:05:35 +0000 (12:05 -0700)
Fixes error codepath when a malformed commit object has a header line
chomped in the middle.

pretty.c
index 02a0a2bb43570fec656c4152454fa67743111a2c..dc57e5b3296b0e580d6db62c3556f0ff3d52307f 100644 (file)
--- a/pretty.c
+++ b/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)