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

Re: [PATCH 1/3] cache-tree: refactor verification to return error codes

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 17, 2024, 17:05 UTC
Message-ID
<CAPig+cQ472dzChHKgrL_DNRe4KMNHNVxR1Qh3n6M=OgtBkG1+w@mail.gmail.com>
In-Reply-To
<1f13bc0e3259ea9b76f1417303a8ef063f3a7cbe.1726556195.git.ps@pks.im>
On Tue, Sep 17, 2024 at 3:13 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 10 quoted lines
> The function `cache_tree_verify()` will `BUG()` whenever it finds that
> the cache-tree extension of the index is corrupt. The function is thus
> inherently untestable because the resulting call to `abort()` will be
> detected by our testing framework and labelled an error. And rightfully
> so: it shouldn't ever be possible to hit bugs, as they should indicate a
> programming error rather than corruption of on-disk state.
>
> Refactor the function to instead return error codes. This also ensures
> that the function can be used e.g. by git-fsck(1) without the whole
> process dying.
Makes sense.
Show 12 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> diff --git a/cache-tree.c b/cache-tree.c
> @@ -890,18 +892,23 @@ static int verify_one(struct repository *r,
>         struct strbuf tree_buf = STRBUF_INIT;
>         for (i = 0; i < it->subtree_nr; i++) {
>                 strbuf_addf(path, "%s/", it->down[i]->name);
> -               if (verify_one(r, istate, it->down[i]->cache_tree, path))
> -                       return 1;
> +               ret = verify_one(r, istate, it->down[i]->cache_tree, path);
> +               if (ret)
> +                       goto out;

Assuming I am understanding correctly that the original code was leaking the strbuf by returning early, I was surprised that the commit message didn't mention that the patch is also fixing the leak. (Probably not worth a reroll, though.)

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 13 in “cache-tree: fix segfaults with invalid cache-trees”
  1. 0/3 cache-tree: fix segfaults with invalid cache-treesPatrick Steinhardt, Sep 17, 2024
  2. 1/3 cache-tree: refactor verification to return error codesPatrick Steinhardt, Sep 17, 2024
  3. Eric SunshineSep 17, 2024
  4. Patrick SteinhardtSep 18, 2024
  5. 2/3 cache-tree: detect mismatching number of index entriesPatrick Steinhardt, Sep 17, 2024
  6. Junio C HamanoSep 19, 2024
  7. Patrick SteinhardtSep 24, 2024
  8. Junio C HamanoSep 24, 2024
  9. 3/3 unpack-trees: detect mismatching number of cache-tree/index entriesPatrick Steinhardt, Sep 17, 2024
  10. 0/3 cache-tree: fix segfaults with invalid cache-treesPatrick Steinhardt, Oct 7, 2024
  11. 1/3 cache-tree: refactor verification to return error codesPatrick Steinhardt, Oct 7, 2024
  12. 2/3 cache-tree: detect mismatching number of index entriesPatrick Steinhardt, Oct 7, 2024
  13. 3/3 unpack-trees: detect mismatching number of cache-tree/index entriesPatrick Steinhardt, Oct 7, 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.