Skip to content

Commit 3324dd8

Browse files
dschogitster
authored andcommitted
commit -S: avoid invalid pointer with empty message
While it is not recommended, fsck.c says: 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. A commit object with only a header without any body, not even without a blank line after the header, is valid. So let's tread carefully here. strstr("\n\n") may find nothing and return NULL. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e465796 commit 3324dd8

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)