tree-diff: don't access hash of NULL object_id pointer
authorRené Scharfe <l.s.r@web.de>
Sat, 15 Jul 2017 17:18:51 +0000 (19:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Jul 2017 21:49:36 +0000 (14:49 -0700)
The object_id pointers can be NULL for invalid entries. Don't try to
dereference them and pass NULL along to fill_tree_descriptor() instead,
which handles them just fine.

Found with Clang's UBSan.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tree-diff.c
index 467e3817243567dadfaf853fddef8a0ef894f270..7f7ddda4ea51e32f67ded46d73f5c0b1c8adb6d6 100644 (file)
@@ -422,8 +422,9 @@ static struct combine_diff_path *ll_diff_tree_paths(
         *   diff_tree_oid(parent, commit) )
         */
        for (i = 0; i < nparent; ++i)
-               tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash);
-       ttree = fill_tree_descriptor(&t, oid->hash);
+               tptree[i] = fill_tree_descriptor(&tp[i],
+                               parents_oid[i] ? parents_oid[i]->hash : NULL);
+       ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL);
 
        /* Enable recursion indefinitely */
        opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);