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

Re: [PATCH 05/12] process_tree/blob: check for NULL

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 19, 2008, 21:31 UTC
Message-ID
<7vodaciqg5.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<12033676833341-git-send-email-mkoegler@auto.tuwien.ac.at>
Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
Show 30 quoted lines
> As these functions are directly called with the result
> from lookup_tree/blob, they must handle NULL.
>
> Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
> ---
>  list-objects.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/list-objects.c b/list-objects.c
> index 4ef58e7..c8b8375 100644
> --- a/list-objects.c
> +++ b/list-objects.c
> @@ -18,6 +18,8 @@ static void process_blob(struct rev_info *revs,
>  
>  	if (!revs->blob_objects)
>  		return;
> +	if (!obj)
> +		die("bad blob object");
>  	if (obj->flags & (UNINTERESTING | SEEN))
>  		return;
>  	obj->flags |= SEEN;
> @@ -69,6 +71,8 @@ static void process_tree(struct rev_info *revs,
>  
>  	if (!revs->tree_objects)
>  		return;
> +	if (!obj)
> +		die("bad tree object");
>  	if (obj->flags & (UNINTERESTING | SEEN))
>  		return;
>  	if (parse_tree(tree) < 0)
I think these are in line with process_tree() that barfs like this:
	if (parse_tree(tree) < 0)
		die("bad tree object %s", sha1_to_hex(obj->sha1));

in the existing codepath, but these new die() callsites lose information.

It would be nicer if we can report what entry (name) in which tree object (sha1) lead to this die(). The same comment applies to [09/12].

Nevertheless, this is an improvement compared to accessing NULL->flags and dying with segv. I'll queue.

Thanks.
Previous: Martin Koegler
Message 13 of 13 in “read_object_with_reference: don't read beyond the buffer”
  1. 01/12 read_object_with_reference: don't read beyond the bufferMartin Koegler, Feb 18, 2008
  2. 02/12 get_sha1_oneline: check return value of parse_objectMartin Koegler, Feb 18, 2008
  3. 03/12 mark_blob/tree_uninteresting: check for NULLMartin Koegler, Feb 18, 2008
  4. 04/12 add_one_tree: handle NULL from lookup_treeMartin Koegler, Feb 18, 2008
  5. 05/12 process_tree/blob: check for NULLMartin Koegler, Feb 18, 2008
  6. 06/12 check results of parse_commit in merge_basesMartin Koegler, Feb 18, 2008
  7. 07/12 peel_onion: handle NULLMartin Koegler, Feb 18, 2008
  8. 08/12 process_tag: handle tag->tagged == NULLMartin Koegler, Feb 18, 2008
  9. 09/12 process_tree/blob: check for NULLMartin Koegler, Feb 18, 2008
  10. 10/12 revision.c: handle tag->tagged == NULLMartin Koegler, Feb 18, 2008
  11. 11/12 parse_commit: don't fail, if object is NULLMartin Koegler, Feb 18, 2008
  12. 12/12 check return value from parse_commitMartin Koegler, Feb 18, 2008
  13. Junio C HamanoFeb 19, 2008

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.