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

Re: [PATCH] builtin/clone: fix segfault when using --revision on some servers

From
Friedli Adrian LCPF-CH <adrian.friedli@mt.com>
Date
Mar 12, 2026, 12:34 UTC
Message-ID
<DB8SPR01MB0009F61C462C819CDFF80ED7EA44A@DB8SPR01MB0009.eurprd03.prod.outlook.com>
In-Reply-To
<xmqqwlzozqgb.fsf@gitster.g>
Hi
Thanks for your response.
Show 16 quoted lines
> > In the bad case the server ignores
> > `transport_ls_refs_options.ref_prefixes` and in `cmd_clone()` the
> > linked list `refs` returned by `transport_get_remote_refs()` contains
> > many items, amongst others "HEAD". `remote_head` returned by
> > `find_ref_by_name()` is not NULL and `remote_head_points_at` returned
> > by `guess_remote_head()` is not NULL but its field `peer_ref` is NULL.
> > Because `remote_head_points_at` is not NULL the guard in
> > `update_remote_refs()` does not skip the affected code and
> > `remote_head_points_at->peer_ref->name` is accessed, which causes a
> > segfault later on.
> 
> The description makes it sound more like this code is perfectly fine, and the
> problem is in guess_remote_head() that reads the refs list and includes such a
> bogus thing with no peer_ref in the result of its guessing.  There are 4 direct
> callers to guess_remote_head() including this one---wouldn't they also obtain
> a list with such a ref entry?

I traced the 3 other callers to guess_remote_head() and none of them has a problem if peer_ref is NULL. In get_expanded_map() there is even a condition `if (cpy->peer_ref)`, which indicates peer_ref is allowed to be NULL.

Show 8 quoted lines
> Or is guess_remote_head() correct in that some uses of its result do not mind
> such a ref with no peer_ref, but only this code path wants to see a ref with
> peer_ref?  If that is the case, then shouldn't the code this patch touches be
> looping over remote_head_points_at to see if there is one with a peer_ref and
> use that?  The original is assuming that remote_head_points_at that is not
> NULL has a valid and usable entry at the beginning of the list, but if that
> assumption does not hold and we are getting multiple hits, wouldn't it be
> possible that a good entry is hidden behind a bad one in the list of refs?

In this path, guess_remote_head() is called without the REMOTE_GUESS_HEAD_ALL flag, which makes it return only the most likely ref.

Kind regards, Adrian

Previous: Junio C HamanoNext: Adrian Friedli
Message 3 of 4 in “builtin/clone: fix segfault when using --revision on some servers”
  1. builtin/clone: fix segfault when using --revision on some serversAdrian Friedli, Mar 6, 2026
  2. Junio C HamanoMar 6, 2026
  3. Friedli Adrian LCPF-CHMar 12, 2026
  4. Adrian FriedliApr 9, 2026

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.