]> git.ipfire.org Git - thirdparty/git.git/commitdiff
serve: reject commands used as capabilities
authorJeff King <peff@peff.net>
Wed, 15 Sep 2021 18:36:36 +0000 (14:36 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Sep 2021 19:25:19 +0000 (12:25 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
serve.c
t/t5701-git-serve.sh

diff --git a/serve.c b/serve.c
index db5ecfed2dae53c8a1dd32771deb588411393b19..b3fe9b5126a3347784d501e296102ab87cc4c5ab 100644 (file)
--- a/serve.c
+++ b/serve.c
@@ -201,7 +201,7 @@ static int receive_client_capability(const char *key)
        const char *value;
        const struct protocol_capability *c = get_capability(key, &value);
 
-       if (!c || !c->advertise(the_repository, NULL))
+       if (!c || c->command || !c->advertise(the_repository, NULL))
                return 0;
 
        if (c->receive)
index 2e51886defe3773870b5cd5db7b1926ad438e0a5..3928424e1bb81c9342a84ae19205343b562668ad 100755 (executable)
@@ -72,6 +72,27 @@ test_expect_success 'request invalid command' '
        test_i18ngrep "invalid command" err
 '
 
+test_expect_success 'request capability as command' '
+       test-tool pkt-line pack >in <<-EOF &&
+       command=agent
+       object-format=$(test_oid algo)
+       0000
+       EOF
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
+       grep invalid.command.*agent err
+'
+
+test_expect_success 'request command as capability' '
+       test-tool pkt-line pack >in <<-EOF &&
+       command=ls-refs
+       object-format=$(test_oid algo)
+       fetch
+       0000
+       EOF
+       test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
+       grep unknown.capability err
+'
+
 test_expect_success 'requested command is command=value' '
        test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs=whatever