]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: check result of resolve_ref_unsafe
authorAndrey Okoshkin <a.okoshkin@samsung.com>
Fri, 20 Oct 2017 11:03:28 +0000 (14:03 +0300)
committerJunio C Hamano <gitster@pobox.com>
Sat, 21 Oct 2017 12:23:44 +0000 (21:23 +0900)
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>
builtin/commit.c

index 1a0da71a43cfef8818b52a3d27131e340725cef2..b528290902da1153849e6cf4560488c553a1e38a 100644 (file)
@@ -1483,6 +1483,8 @@ static void print_summary(const char *prefix, const struct object_id *oid,
        diff_setup_done(&rev.diffopt);
 
        head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
+       if (!head)
+               die_errno(_("unable to resolve HEAD after creating commit"));
        if (!strcmp(head, "HEAD"))
                head = _("detached HEAD");
        else