Skip to content

Commit 7ed0988

Browse files
René Scharfegitster
authored andcommitted
Make "--pretty=format" parser a bit more careful.
When a commit message that does not have a terminating LF is read in and the memory that was allocated to read it happens to have a LF immediately after that, the code was not careful and went past the terminating NUL. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cc21682 commit 7ed0988

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pretty.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static void parse_commit_header(struct format_commit_context *context)
412412
if (i == eol) {
413413
state++;
414414
/* strip empty lines */
415-
while (msg[eol + 1] == '\n')
415+
while (msg[eol] == '\n' && msg[eol + 1] == '\n')
416416
eol++;
417417
} else if (!prefixcmp(msg + i, "author ")) {
418418
context->author.off = i + 7;
@@ -425,6 +425,8 @@ static void parse_commit_header(struct format_commit_context *context)
425425
context->encoding.len = eol - i - 9;
426426
}
427427
i = eol;
428+
if (!msg[i])
429+
break;
428430
}
429431
context->body_off = i;
430432
context->commit_header_parsed = 1;

0 commit comments

Comments
 (0)