commit: check result of resolve_ref_unsafe

Add check of the resolved HEAD reference while printing of a commit summary. resolve_ref_unsafe() may return NULL pointer if underlying calls of lstat() or open() fail in files_read_raw_ref(). Such situation can be caused by race: file becomes inaccessible to this moment. Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Andrey Okoshkin committed Oct 20, 2017 at 14:03 UTC c26de08370ad5d927d93dbe6fb46103caabb889c
1 file changed +2
builtin/commit.c
+2
@@ -1483,6 +1483,8 @@ static void print_summary(const char *prefix, const struct object_id *oid,
1483 diff_setup_done(&rev.diffopt);
1484
1485 head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
1486 + if (!head)
1487 + die_errno(_("unable to resolve HEAD after creating commit"));
1488 if (!strcmp(head, "HEAD"))
1489 head = _("detached HEAD");
1490 else