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

Re: [PATCH] bundle-uri.c: Fix double increment in depth

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 21, 2024, 16:59 UTC
Message-ID
<xmqqfrt6nsds.fsf@gitster.g>
In-Reply-To
<CAP8UFD3jGVaO2JdKE0H22mf4E8YBxrEwuGqJuyeRGBVh==23NQ@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> writes:
Show 12 quoted lines
> On Fri, Jun 21, 2024 at 11:23 AM Toon Claes <toon@iotcl.com> wrote:
>>
>> A bundle URI can serve a gitformat-bundle(5) or a bundle list. This
>> plain text file is in the Git config format containing other bundle
>> URIs. To avoid these bundle lists to nest too deep, we've set a limit
>> with `max_bundle_uri_depth`.
>
> Yeah, max_bundle_uri_depth seems to be hardcoded to 4.
>
>> Although, when walk through the tree of
>
> s/walk/walking/
While you are typofixing ...
> Subject: Re: [PATCH] bundle-uri.c: Fix double increment in depth
... also "Fix" -> "fix".
Show 22 quoted lines
>> bundles, the current depth is incremented in download_bundle_list() and
>> then calls download_bundle_to_file(), which also increments the depth.
>
> s/and then calls/which then calls/
>
>> Remove the increment in download_bundle_to_file().
>
> The increment is removed by replacing:
>
>     fetch_bundle_uri_internal( ..., ctx->depth + 1, ...)
>
> with:
>
>     fetch_bundle_uri_internal( ..., ctx->depth, ...)
>
> in download_bundle_to_file(). Ok.
>
> It looks like there is another similar call to that function like this:
>
> fetch_bundle_uri_internal( ... , ctx.depth + 1, ... )
>
> in fetch_bundles_by_token() though.

I have to wonder if the code should pass the whole ctx around, instead of passing depth separately, and increment it at the single place that matters, in order to reduce the chance of similar problem happening. The place that matters the recursion depth can be the download_bundle_list() function---that is the one that controls the recursion, and it is incrementing the depth for the calls it makes (via the for_all_* callback mechanism). Alternatively, it can be the fetch_bundle_uri_internal() function where actual copying, for which we do want to enforce the depth limit, happens. The function even has the code for depth limit, so having an increment next to it may make it more readable and understandable.

So instead of taking ctx->r, ctx->depth+1, and ctx->list separately, shouldn't fetch_bundle_uri_internal() take the whole ctx and use ctx->depth (not +1---incrementing it is not its business) and the whole (current and future) problem like this goes away, no?

Previous: Christian CouderNext: Eric Sunshine
Message 3 of 4 in “bundle-uri.c: Fix double increment in depth”
  1. bundle-uri.c: Fix double increment in depthToon Claes, Jun 21, 2024
  2. Christian CouderJun 21, 2024
  3. Junio C HamanoJun 21, 2024
  4. Eric SunshineJun 21, 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.