Skip to content

Commit 0ab7eec

Browse files
peffgitster
authored andcommitted
serve: reject commands used as capabilities
Our table of v2 "capabilities" contains everything we might tell the client we support. But there are differences in how we expect the client to respond. Some of the entries are true capabilities (i.e., we expect the client to say "yes, I support this"), and some are ones we expect them to send as commands (with "command=ls-refs" or similar). When we receive a capability used as a command, we complain about that. But when we receive a command used as a capability (e.g., just "ls-refs" in a pkt-line by itself), we silently ignore it. This isn't really hurting anything (clients shouldn't send it, and we'll ignore it), but we can tighten up the protocol to match what we expect to happen. There are two new tests here. The first one checks a capability used as a command, which already passes. The second tests a command as a capability, which this patch fixes. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 108c265 commit 0ab7eec

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

serve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int receive_client_capability(const char *key)
201201
const char *value;
202202
const struct protocol_capability *c = get_capability(key, &value);
203203

204-
if (!c || !c->advertise(the_repository, NULL))
204+
if (!c || c->command || !c->advertise(the_repository, NULL))
205205
return 0;
206206

207207
if (c->receive)

t/t5701-git-serve.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ test_expect_success 'request invalid command' '
7272
test_i18ngrep "invalid command" err
7373
'
7474

75+
test_expect_success 'request capability as command' '
76+
test-tool pkt-line pack >in <<-EOF &&
77+
command=agent
78+
object-format=$(test_oid algo)
79+
0000
80+
EOF
81+
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
82+
grep invalid.command.*agent err
83+
'
84+
85+
test_expect_success 'request command as capability' '
86+
test-tool pkt-line pack >in <<-EOF &&
87+
command=ls-refs
88+
object-format=$(test_oid algo)
89+
fetch
90+
0000
91+
EOF
92+
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
93+
grep unknown.capability err
94+
'
95+
7596
test_expect_success 'requested command is command=value' '
7697
test-tool pkt-line pack >in <<-EOF &&
7798
command=ls-refs=whatever

0 commit comments

Comments
 (0)