All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH resend] builtin/clone: fix segfault when using --revision on some servers
@ 2026-07-23 14:43 Adrian Friedli
  2026-07-23 15:43 ` Junio C Hamano
  2026-07-24 12:41 ` [PATCH v2] builtin/clone: fix segfault when using --revision with protocol v0 Adrian Friedli
  0 siblings, 2 replies; 6+ messages in thread
From: Adrian Friedli @ 2026-07-23 14:43 UTC (permalink / raw)
  To: git; +Cc: Adrian Friedli

Fix a segfault when a server advertises more refs than requested when
using the --revision argument.

Signed-off-by: Adrian Friedli <adrian.friedli@mt.com>
---
The segfault can be reproduced by e.g.

git clone --revision=refs/heads/main \
https://dev.azure.com/public-git/sample/_git/sample

In the good case the server respects
`transport_ls_refs_options.ref_prefixes` and in `cmd_clone()` the linked
list `refs` returned by `transport_get_remote_refs()` only contains a
single item, which is the ref requested with the --revision argument.
Both `remote_head` returned by `find_ref_by_name()` and
`remote_head_points_at` returned by `guess_remote_head()` are NULL. The
guard in `update_remote_refs()` skips a the affected code because
`remote_head_points_at` is NULL.

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.

 builtin/clone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 9d08cd8722..bd0c6f5d56 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -557,7 +557,7 @@ static void update_remote_refs(const struct ref *refs,
 			write_followtags(refs, msg);
 	}
 
-	if (remote_head_points_at && !option_bare) {
+	if (remote_head_points_at && remote_head_points_at->peer_ref && !option_bare) {
 		struct strbuf head_ref = STRBUF_INIT;
 		strbuf_addstr(&head_ref, branch_top);
 		strbuf_addstr(&head_ref, "HEAD");
-- 
2.55.0.379.g54b6532b97


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-24 16:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 14:43 [PATCH resend] builtin/clone: fix segfault when using --revision on some servers Adrian Friedli
2026-07-23 15:43 ` Junio C Hamano
2026-07-23 16:10   ` Junio C Hamano
2026-07-24 12:37     ` Adrian Friedli
2026-07-24 16:04       ` Junio C Hamano
2026-07-24 12:41 ` [PATCH v2] builtin/clone: fix segfault when using --revision with protocol v0 Adrian Friedli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.