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

Re: [PATCH] get_oid: handle NULL repo->index

From
Duy Nguyen <pclouds@gmail.com>
Date
May 15, 2019, 09:29 UTC
Message-ID
<CACsJy8BS8NR6aZR29VLYUrRjBE_oyzH=L6X7CSpCO9G+sPjcbA@mail.gmail.com>
In-Reply-To
<xmqqh89w70w8.fsf@gitster-ct.c.googlers.com>
On Wed, May 15, 2019 at 12:16 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
>
> Jeff King <peff@peff.net> writes:
>
> > Also from my earlier message, if you missed it:
> >
> >   I also wondered if we should simply allocate an empty index whenever
> >   we have a non-toplevel "struct repository", which might be less
> >   surprising to other callers. I don't have a strong opinion either way.
> >   I did grep around for other callers which might have similar problems,
> >   but couldn't find any.
>
> That is an approach to make it harder to make mistakes by accepting
> possibly a small wasted resource; but at that point, I think calling
> repo_read_index() unconditionally from here and similar places would
> be a simpler fix in the same spirit.

For repo_read_index() case, maybe. But we have a lot of "r(epo)->index->something". All or most of these references traditionally are the_index.something, which is always safe to dereference. Submodule repos with the optionally NULL repo->index break this assumption.

So either we audit all the code and make sure "repo->index" cannot be NULL because repo_read_index() has been called before (and may have to repeat auditing), or we just stick to the old assumption and make sure repo->index is not NULL from the beginning. This makes me think the small extra resource is worth it. Much less time will be spent on similar issues now and in the future.

PS. Sorry Jeff for the noise. I should have waited until I come home and can read your mail more carefully.

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 16 in “new segfault in master (6a6c0f10a70a6eb1)”
  1. Eric WongMay 11, 2019
  2. Jeff KingMay 11, 2019
  3. Jeff KingMay 11, 2019
  4. Duy NguyenMay 12, 2019
  5. get_oid: handle NULL repo->indexJeff King, May 14, 2019
  6. Eric WongMay 14, 2019
  7. Duy NguyenMay 15, 2019
  8. Jeff KingMay 15, 2019
  9. Junio C HamanoMay 15, 2019
  10. Duy NguyenMay 15, 2019
  11. Junio C HamanoMay 16, 2019
  12. repository.c: always allocate 'index' at repo init timeNguyễn Thái Ngọc Duy, May 19, 2019
  13. Jeff KingMay 20, 2019
  14. Duy NguyenMay 21, 2019
  15. Jeff KingMay 21, 2019
  16. Junio C HamanoMay 28, 2019

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.