serve: reject valueless promisor-remote capability

d460267613 (Add 'promisor-remote' capability to protocol v2,
2025-02-18) added a receive callback which passes the capability value
directly to mark_promisor_remotes_as_accepted(). However, a client can
send the capability name without an '=' or value, in which case
get_capability() supplies NULL and strbuf_split_str() dereferences it.

Reject the missing argument before parsing it, and add a test covering
this case.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
main
Elijah Newren 2026-08-12 06:39:43 +00:00 committed by Junio C Hamano
parent e9019fcafe
commit dd6b35ff71
2 changed files with 14 additions and 0 deletions

View File

@ -46,6 +46,9 @@ static int promisor_remote_advertise(struct repository *r,
static void promisor_remote_receive(struct repository *r,
const char *remotes)
{
if (!remotes)
die("promisor-remote capability requires an argument");

mark_promisor_remotes_as_accepted(r, remotes);
}


View File

@ -69,6 +69,17 @@ test_expect_success 'request invalid capability' '
test_grep "unknown capability" err
'

test_expect_success 'promisor-remote capability requires an argument' '
test-tool pkt-line pack >in <<-EOF &&
command=ls-refs
object-format=$(test_oid algo)
promisor-remote
0000
EOF
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
test_grep "promisor-remote capability requires an argument" err
'

test_expect_success 'request with no command' '
test-tool pkt-line pack >in <<-EOF &&
agent=git/test