git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 30/33] tree-diff: convert diff_tree_paths to struct object_id

From
René Scharfe <l.s.r@web.de>
Date
Jul 15, 2017, 17:18 UTC
Message-ID
<28328b72-40c0-f6bb-09dc-574ca33ce622@web.de>
In-Reply-To
<20170530173109.54904-31-bmwill@google.com>
Am 30.05.2017 um 19:31 schrieb Brandon Williams:
Show 17 quoted lines
> @@ -273,21 +274,20 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
>   	}
>   
>   	if (recurse) {
> -		const unsigned char **parents_sha1;
> +		const struct object_id **parents_oid;
>   
> -		FAST_ARRAY_ALLOC(parents_sha1, nparent);
> +		FAST_ARRAY_ALLOC(parents_oid, nparent);
>   		for (i = 0; i < nparent; ++i) {
>   			/* same rule as in emitthis */
>   			int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
>   
> -			parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash
> -						    : NULL;
> +			parents_oid[i] = tpi_valid ? tp[i].entry.oid : NULL;
>   		}
So elements of parents_oid can be NULL...
Show 6 quoted lines
>   
>   		strbuf_add(base, path, pathlen);
>   		strbuf_addch(base, '/');
> -		p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt);
> -		FAST_ARRAY_FREE(parents_sha1, nparent);
> +		p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt);
... and we pass that array to ll_diff_tree_paths()...
Show 31 quoted lines
> +		FAST_ARRAY_FREE(parents_oid, nparent);
>   	}
>   
>   	strbuf_setlen(base, old_baselen);
> @@ -312,7 +312,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base,
>   
>   
>   /*
> - * generate paths for combined diff D(sha1,parents_sha1[])
> + * generate paths for combined diff D(sha1,parents_oid[])
>    *
>    * Resulting paths are appended to combine_diff_path linked list, and also, are
>    * emitted on the go via opt->pathchange() callback, so it is possible to
> @@ -404,8 +404,8 @@ static inline void update_tp_entries(struct tree_desc *tp, int nparent)
>   }
>   
>   static struct combine_diff_path *ll_diff_tree_paths(
> -	struct combine_diff_path *p, const unsigned char *sha1,
> -	const unsigned char **parents_sha1, int nparent,
> +	struct combine_diff_path *p, const struct object_id *oid,
> +	const struct object_id **parents_oid, int nparent,
>   	struct strbuf *base, struct diff_options *opt)
>   {
>   	struct tree_desc t, *tp;
> @@ -422,8 +422,8 @@ 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_sha1[i]);
> -	ttree = fill_tree_descriptor(&t, sha1);
> +		tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash);

... and here we are in that function, dereferencing a pointer that may be NULL.

> +	ttree = fill_tree_descriptor(&t, oid->hash);
oid here can also be NULL, but I think that's not as easy to see.
-- >8 --
Subject: [PATCH] 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>
---
fill_tree_descriptor() can easily be converted to object_id, by the
way, which would get us rid of the extra check introduced here, but
this patch is meant as a minimal fix.
 tree-diff.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tree-diff.c b/tree-diff.c
index bd6d65a409..2357f72899 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -421,8 +421,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);
-- 
2.13.3
Previous: Junio C HamanoNext: brian m. carlson
Message 31 of 66 in “object id conversion (grep and diff)”
  1. 00/33 object id conversion (grep and diff)Brandon Williams, May 30, 2017
  2. 01/33 notes: convert internal structures to struct object_idBrandon Williams, May 30, 2017
  3. 03/33 notes: convert for_each_note to struct object_idBrandon Williams, May 30, 2017
  4. 05/33 notes: convert format_display_notes to struct object_idBrandon Williams, May 30, 2017
  5. 06/33 builtin/notes: convert to struct object_idBrandon Williams, May 30, 2017
  6. 02/33 notes: convert internal parts to struct object_idBrandon Williams, May 30, 2017
  7. 04/33 notes: make get_note return pointer to struct object_idBrandon Williams, May 30, 2017
  8. René ScharfeJul 15, 2017
  9. Brandon WilliamsJul 17, 2017
  10. 09/33 diff: convert get_stat_data to struct object_idBrandon Williams, May 30, 2017
  11. 07/33 notes: convert some accessor functions to struct object_idBrandon Williams, May 30, 2017
  12. 08/33 grep: convert to struct object_idBrandon Williams, May 30, 2017
  13. Junio C HamanoJun 2, 2017
  14. 15/33 diff: convert reuse_worktree_file to struct object_idBrandon Williams, May 30, 2017
  15. 10/33 diff: convert diff_index_show_file to struct object_idBrandon Williams, May 30, 2017
  16. 19/33 combine-diff: convert diff_tree_combined to struct object_idBrandon Williams, May 30, 2017
  17. 14/33 diff: convert fill_filespec to struct object_idBrandon Williams, May 30, 2017
  18. 21/33 tree-diff: convert diff_root_tree_sha1 to struct object_idBrandon Williams, May 30, 2017
  19. 24/33 notes-merge: convert find_notes_merge_pair_ps to struct object_idBrandon Williams, May 30, 2017
  20. 18/33 diff: convert diff_flush_patch_id to struct object_idBrandon Williams, May 30, 2017
  21. 25/33 notes-merge: convert verify_notes_filepair to struct object_idBrandon Williams, May 30, 2017
  22. Stefan BellerMay 31, 2017
  23. Junio C HamanoJun 2, 2017
  24. Brandon WilliamsJun 2, 2017
  25. Junio C HamanoJun 2, 2017
  26. 30/33 tree-diff: convert diff_tree_paths to struct object_idBrandon Williams, May 30, 2017
  27. Stefan BellerMay 31, 2017
  28. Jeff KingMay 31, 2017
  29. Jeff KingMay 31, 2017
  30. Junio C HamanoJun 2, 2017
  31. René ScharfeJul 15, 2017
  32. brian m. carlsonJul 15, 2017
  33. 26/33 notes-merge: convert write_note_to_worktree to struct object_idBrandon Williams, May 30, 2017
  34. 29/33 tree-diff: convert try_to_follow_renames to struct object_idBrandon Williams, May 30, 2017
  35. 20/33 combine-diff: convert find_paths_* to struct object_idBrandon Williams, May 30, 2017
  36. Stefan BellerMay 31, 2017
  37. Junio C HamanoJun 2, 2017
  38. 23/33 notes-merge: convert merge_from_diffs to struct object_idBrandon Williams, May 30, 2017
  39. Stefan BellerMay 31, 2017
  40. Junio C HamanoJun 2, 2017
  41. 22/33 notes-merge: convert notes_merge* to struct object_idBrandon Williams, May 30, 2017
  42. Stefan BellerMay 31, 2017
  43. brian m. carlsonMay 31, 2017
  44. Junio C HamanoJun 2, 2017
  45. Brandon WilliamsJun 2, 2017
  46. 33/33 diff: rename diff_fill_sha1_info to diff_fill_oid_infoBrandon Williams, May 30, 2017
  47. 31/33 tree-diff: convert path_appendnew to object_idBrandon Williams, May 30, 2017
  48. Junio C HamanoJun 2, 2017
  49. 27/33 diff-tree: convert diff_tree_sha1 to struct object_idBrandon Williams, May 30, 2017
  50. 32/33 diffcore-rename: use is_empty_blob_oidBrandon Williams, May 30, 2017
  51. 28/33 builtin/diff-tree: cleanup references to sha1Brandon Williams, May 30, 2017
  52. Junio C HamanoJun 2, 2017
  53. 17/33 patch-ids: convert to struct object_idBrandon Williams, May 30, 2017
  54. 16/33 diff: finish conversion for prepare_temp_file to struct object_idBrandon Williams, May 30, 2017
  55. Stefan BellerMay 31, 2017
  56. 11/33 diff: convert diff_addremove to struct object_idBrandon Williams, May 30, 2017
  57. 12/33 diff: convert run_diff_files to struct object_idBrandon Williams, May 30, 2017
  58. 13/33 diff: convert diff_change to struct object_idBrandon Williams, May 30, 2017
  59. brian m. carlsonMay 31, 2017
  60. Brandon WilliamsJun 2, 2017
  61. Junio C HamanoJun 2, 2017
  62. Junio C HamanoJun 2, 2017
  63. Junio C HamanoJun 2, 2017
  64. Brandon WilliamsJun 2, 2017
  65. Junio C HamanoJun 2, 2017
  66. Brandon WilliamsJun 5, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.