While it is not recommended, `git fsck` says that:

        Not having a body is not a crime [...]

... which means that we cannot assume that the commit buffer contains an
empty line to separate header from body (essentially saying that there
is only a header).

So let's tread carefully here.

Signed-off-by: Johannes Schindelin <[email protected]>
---
 commit.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/commit.c b/commit.c
index 24d4715..0bb51a2 100644
--- a/commit.c
+++ b/commit.c
@@ -1090,11 +1090,15 @@ static const int gpg_sig_header_len = 
sizeof(gpg_sig_header) - 1;
 
 static int do_sign_commit(struct strbuf *buf, const char *keyid)
 {
+       const char *eoh = strstr(buf->buf, "\n\n");
        struct strbuf sig = STRBUF_INIT;
        int inspos, copypos;
 
        /* find the end of the header */
-       inspos = strstr(buf->buf, "\n\n") - buf->buf + 1;
+       if (!eoh)
+               inspos = buf->len;
+       else
+               inspos = eoh - buf->buf + 1;
 
        if (!keyid || !*keyid)
                keyid = get_signing_key();
-- 
2.9.0.270.g810e421


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to