tree-diff: don't access hash of NULL object_id pointer

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>

René Scharfe committed Jul 15, 2017 at 19:18 UTC fb04dced9c6510176f06953d2cd6a239703401f1
1 file changed +3 -2
tree-diff.c
+3 -2
@@ -422,8 +422,9 @@ static struct combine_diff_path *ll_diff_tree_paths(
422 * diff_tree_oid(parent, commit) )
423 */
424 for (i = 0; i < nparent; ++i)
425 - tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash);
426 - ttree = fill_tree_descriptor(&t, oid->hash);
425 + tptree[i] = fill_tree_descriptor(&tp[i],
426 + parents_oid[i] ? parents_oid[i]->hash : NULL);
427 + ttree = fill_tree_descriptor(&t, oid ? oid->hash : NULL);
428
429 /* Enable recursion indefinitely */
430 opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE);