summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2012-06-01 13:01:33 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2012-06-01 13:01:33 -0700
commit6c227410b5e1bb014896514f90be55503c4a26c9 (patch)
tree94764329b01846d59062ca0967961c6d93ab6b95
parentMerge branch 'jk/format-person-part-buffer-limit' into maint (diff)
parentavoid segfault when reading header of malformed commits (diff)
downloadtgif-6c227410b5e1bb014896514f90be55503c4a26c9.tar.xz
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
-rw-r--r--pretty.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/pretty.c b/pretty.c
index 986e114e0c..8b1ea9ffad 100644
--- 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)