Skip to content

Commit 0dfed92

Browse files
peffgitster
authored andcommitted
git-am: handle missing "author" when parsing commit
We try to parse the "author" line out of a commit buffer. We handle the case that split_ident_line() doesn't work, but we don't do any error checking that we found an "author" line in the first place! This would cause us to segfault on such a corrupt object. Let's put in an explicit NULL check (we can just die(), which is what a bogus split would do, too). As a bonus, this silences a warning when compiling with gcc 9.2.1 using "-flto -O3", which claims that ident_len may be uninitialized (it would only be if we had a NULL here). Reported-by: Stephan Beyer <[email protected]> Helped-by: René Scharfe <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 745f681 commit 0dfed92

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/am.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,9 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
12721272
buffer = logmsg_reencode(commit, NULL, get_commit_output_encoding());
12731273

12741274
ident_line = find_commit_header(buffer, "author", &ident_len);
1275-
1275+
if (!ident_line)
1276+
die(_("missing author line in commit %s"),
1277+
oid_to_hex(&commit->object.oid));
12761278
if (split_ident_line(&id, ident_line, ident_len) < 0)
12771279
die(_("invalid ident line: %.*s"), (int)ident_len, ident_line);
12781280

0 commit comments

Comments
 (0)