Skip to content

Commit 475495f

Browse files
committed
Merge branch 'js/sign-empty-commit-fix' into maint
"git commit --amend --allow-empty-message -S" for a commit without any message body could have misidentified where the header of the commit object ends. * js/sign-empty-commit-fix: commit -S: avoid invalid pointer with empty message
2 parents ae8daba + 3324dd8 commit 475495f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

commit.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,14 @@ static int do_sign_commit(struct strbuf *buf, const char *keyid)
10921092
{
10931093
struct strbuf sig = STRBUF_INIT;
10941094
int inspos, copypos;
1095+
const char *eoh;
10951096

10961097
/* find the end of the header */
1097-
inspos = strstr(buf->buf, "\n\n") - buf->buf + 1;
1098+
eoh = strstr(buf->buf, "\n\n");
1099+
if (!eoh)
1100+
inspos = buf->len;
1101+
else
1102+
inspos = eoh - buf->buf + 1;
10981103

10991104
if (!keyid || !*keyid)
11001105
keyid = get_signing_key();

0 commit comments

Comments
 (0)