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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 29, 2016 at 16:14 UTC
3324dd8f267cb59cdd42ac33727b6844921d5017
1 file changed
+6
-1
commit.c
+6
-1
@@ -1092,9 +1092,14 @@ static int do_sign_commit(struct strbuf *buf, const char *keyid)
1092
{
1093
struct strbuf sig = STRBUF_INIT;
1094
int inspos, copypos;
1095
+ const char *eoh;
1096
1097
/* 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;
1103
1104
if (!keyid || !*keyid)
1105
keyid = get_signing_key();