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

Re: [PATCH] Always check the return value of `repo_read_object_file()`

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 12, 2024, 23:19 UTC
Message-ID
<fcb8240a-0b97-8554-9eee-8ff2acdb9a8f@gmx.de>
In-Reply-To
<xmqqplx9fdyk.fsf@gitster.g>
Hi Junio,
On Tue, 6 Feb 2024, Junio C Hamano wrote:
Show 18 quoted lines
> > diff --git a/builtin/grep.c b/builtin/grep.c
> > index c8e33f97755..982bcfc4b1d 100644
> > --- a/builtin/grep.c
> > +++ b/builtin/grep.c
> > @@ -571,6 +571,8 @@ static int grep_cache(struct grep_opt *opt,
> >
> >  			data = repo_read_object_file(the_repository, &ce->oid,
> >  						     &type, &size);
> > +			if (!data)
> > +				die(_("unable to read tree %s"), oid_to_hex(&ce->oid));
> >  			init_tree_desc(&tree, data, size);
> >
> >  			hit |= grep_tree(opt, pathspec, &tree, &name, 0, 0);
>
> This caught my attention during today's integration cycle.  Checking
> nullness for data certainly is an improvement, but shouldn't we be
> checking type as well to make sure it is a tree and not a random
> tree-ish or even blob?

That sounds right, but I am already stretching this patch beyond what I am funded to work on, and therefore I need to leave it at the current state.

Ciao, Johannes

Previous: Junio C HamanoNext: Teng Long
Message 14 of 16 in “Always check the return value of `repo_read_object_file()`”
  1. Always check the return value of `repo_read_object_file()`Johannes Schindelin via GitGitGadget, Feb 5, 2024
  2. Karthik NayakFeb 5, 2024
  3. Junio C HamanoFeb 6, 2024
  4. Johannes SchindelinFeb 12, 2024
  5. Kyle LippincottFeb 6, 2024
  6. Johannes SchindelinFeb 9, 2024
  7. Junio C HamanoFeb 9, 2024
  8. Kyle LippincottFeb 9, 2024
  9. Patrick SteinhardtFeb 6, 2024
  10. Junio C HamanoFeb 6, 2024
  11. Johannes SchindelinFeb 9, 2024
  12. Patrick SteinhardtFeb 9, 2024
  13. Junio C HamanoFeb 6, 2024
  14. Johannes SchindelinFeb 12, 2024
  15. Always check the return value of `repo_read_object_file()`Teng Long, Feb 16, 2024
  16. Johannes SchindelinFeb 18, 2024

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.