summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-07-28 11:25:53 -0700
committerJunio C Hamano <gitster@pobox.com>2016-07-28 11:25:53 -0700
commit475495ff5e071c895dca772cb59e277ceff84d84 (patch)
tree47d32127a04df73476f67776e81dca6f4f84ff4e
parentae8daba6019fba266ba7afd88aa642bf6994fe2c (diff)
parent3324dd8f267cb59cdd42ac33727b6844921d5017 (diff)
downloadgit-475495ff5e071c895dca772cb59e277ceff84d84.tar.gz
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
-rw-r--r--commit.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/commit.c b/commit.c
index 24d4715f24..2a90e37519 100644
--- a/commit.c
+++ b/commit.c
@@ -1092,9 +1092,14 @@ static int do_sign_commit(struct strbuf *buf, const char *keyid)
{
struct strbuf sig = STRBUF_INIT;
int inspos, copypos;
+ const char *eoh;
/* find the end of the header */
- inspos = strstr(buf->buf, "\n\n") - buf->buf + 1;
+ eoh = strstr(buf->buf, "\n\n");
+ if (!eoh)
+ inspos = buf->len;
+ else
+ inspos = eoh - buf->buf + 1;
if (!keyid || !*keyid)
keyid = get_signing_key();