* [PATCH] connect: clear v2 server capabilities on handshake
@ 2026-11-19 19:22 Dominik Maier
0 siblings, 0 replies; only message in thread
From: Dominik Maier @ 2026-11-19 19:22 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Patrick Steinhardt, Ivan Frade, Xing Xin,
dmnk+artist, Dominik Maier
process_capabilities_v2() appends capability lines onto the file-static
server_capabilities_v2 vector without clearing entries recorded during
earlier handshakes in the same process. Because server_feature_v2() and
server_supports_feature() return the first matching entry in
server_capabilities_v2, capabilities advertised by an earlier remote
bleed into subsequent connections (including v0/v1 handshakes that skip
process_capabilities_v2() before callers such as get_bundle_uri() query
server_supports_v2("bundle-uri")).
For example, running "git remote show r1 r2" when r1 uses SHA-256 and r2
uses SHA-1 causes the second handshake to read r1's stale
"object-format=sha256" capability and fail with "mismatched object
format", and a stale "session-id" from r1 is logged again for r2 even
when r2 disables transfer.advertiseSID.
Clear server_capabilities_v2 in discover_version() and
process_capabilities_v2().
Signed-off-by: Dominik Maier <dmnk@google.com>
---
connect.c | 3 +++
t/t5702-protocol-v2.sh | 23 +++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/connect.c b/connect.c
index 87d2e8bccd..b620cf2286 100644
--- a/connect.c
+++ b/connect.c
@@ -133,6 +133,7 @@ int server_supports_feature(const char *c, const char *feature,
static void process_capabilities_v2(struct packet_reader *reader)
{
+ strvec_clear(&server_capabilities_v2);
while (packet_reader_read(reader) == PACKET_READ_NORMAL)
strvec_push(&server_capabilities_v2, reader->line);
@@ -144,6 +145,8 @@ enum protocol_version discover_version(struct packet_reader *reader)
{
enum protocol_version version = protocol_unknown_version;
+ strvec_clear(&server_capabilities_v2);
+
/*
* Peek the first line of the server's response to
* determine the protocol version the server is speaking.
diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh
index e5e73eb407..3716e43bb1 100755
--- a/t/t5702-protocol-v2.sh
+++ b/t/t5702-protocol-v2.sh
@@ -548,6 +548,29 @@ test_expect_success 'invalid server-option configuration' '
test_grep "error: missing value for '\''remote.origin.serveroption'\''" err
'
+test_expect_success 'v2 server capabilities do not bleed across in-process handshakes' '
+ test_when_finished "rm -rf cap_r1 cap_r2 cap_client trace2_caps" &&
+ git init --object-format=sha256 cap_r1 &&
+ test_commit -C cap_r1 one &&
+ git -C cap_r1 config transfer.advertiseSID true &&
+
+ git init --object-format=sha1 cap_r2 &&
+ test_commit -C cap_r2 two &&
+ git -C cap_r2 config transfer.advertiseSID false &&
+
+ git init --object-format=sha1 cap_client &&
+ git -C cap_client remote add r1 "file://$(pwd)/cap_r1" &&
+ git -C cap_client remote add r2 "file://$(pwd)/cap_r2" &&
+
+ GIT_TRACE2_EVENT="$(pwd)/trace2_caps" \
+ git -C cap_client -c protocol.version=2 -c transfer.advertiseSID=true \
+ remote show r1 r2 >out &&
+ test_grep "\* remote r2" out &&
+ grep "\"category\":\"transfer\",\"key\":\"server-sid\"" trace2_caps >sids &&
+ # Only r1 advertised session-id; r2 must not inherit it
+ test_line_count = 1 sids
+'
+
test_expect_success 'upload-pack respects config using protocol v2' '
git init server &&
write_script server/.git/hook <<-\EOF &&
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 19:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:22 [PATCH] connect: clear v2 server capabilities on handshake Dominik Maier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox