Skip to content

Commit a922bfa

Browse files
peffgitster
authored andcommitted
upload-pack: only accept packfile-uris if we advertised it
Clients are only supposed to request particular capabilities or features if the server advertised them. For the "packfile-uris" feature, we only advertise it if uploadpack.blobpacfileuri is set, but we always accept a request from the client regardless. In practice this doesn't really hurt anything, as we'd pass the client's protocol list on to pack-objects, which ends up ignoring it. But we should try to follow the protocol spec, and tightening this up may catch buggy or misbehaving clients more easily. Thanks to recent refactoring, we can hoist the config check from upload_pack_advertise() into upload_pack_config(). Note the subtle handling of a value-less bool (which does not count for triggering an advertisement). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a7b229 commit a922bfa

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

t/t5702-protocol-v2.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,25 @@ test_expect_success 'archive with custom path does not request v2' '
778778
! grep ^GIT_PROTOCOL env.trace
779779
'
780780

781+
test_expect_success 'reject client packfile-uris if not advertised' '
782+
{
783+
packetize command=fetch &&
784+
packetize object-format=$(test_oid algo) &&
785+
printf 0001 &&
786+
packetize packfile-uris https &&
787+
packetize done &&
788+
printf 0000
789+
} >input &&
790+
test_must_fail env GIT_PROTOCOL=version=2 \
791+
git upload-pack client <input &&
792+
test_must_fail env GIT_PROTOCOL=version=2 \
793+
git -c uploadpack.blobpackfileuri \
794+
upload-pack client <input &&
795+
GIT_PROTOCOL=version=2 \
796+
git -c uploadpack.blobpackfileuri=anything \
797+
upload-pack client <input
798+
'
799+
781800
# Test protocol v2 with 'http://' transport
782801
#
783802
. "$TEST_DIRECTORY"/lib-httpd.sh

upload-pack.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct upload_pack_data {
113113
unsigned done : 1; /* v2 only */
114114
unsigned allow_ref_in_want : 1; /* v2 only */
115115
unsigned allow_sideband_all : 1; /* v2 only */
116+
unsigned allow_packfile_uris : 1; /* v2 only */
116117
unsigned advertise_sid : 1;
117118
unsigned sent_capabilities : 1;
118119
};
@@ -1362,6 +1363,9 @@ static int upload_pack_config(const char *var, const char *value,
13621363
data->allow_ref_in_want = git_config_bool(var, value);
13631364
} else if (!strcmp("uploadpack.allowsidebandall", var)) {
13641365
data->allow_sideband_all = git_config_bool(var, value);
1366+
} else if (!strcmp("uploadpack.blobpackfileuri", var)) {
1367+
if (value)
1368+
data->allow_packfile_uris = 1;
13651369
} else if (!strcmp("core.precomposeunicode", var)) {
13661370
precomposed_unicode = git_config_bool(var, value);
13671371
} else if (!strcmp("transfer.advertisesid", var)) {
@@ -1647,7 +1651,8 @@ static void process_args(struct packet_reader *request,
16471651
continue;
16481652
}
16491653

1650-
if (skip_prefix(arg, "packfile-uris ", &p)) {
1654+
if (data->allow_packfile_uris &&
1655+
skip_prefix(arg, "packfile-uris ", &p)) {
16511656
string_list_split(&data->uri_protocols, p, ',', -1);
16521657
continue;
16531658
}
@@ -1847,8 +1852,6 @@ int upload_pack_advertise(struct repository *r,
18471852
get_upload_pack_config(r, &data);
18481853

18491854
if (value) {
1850-
char *str = NULL;
1851-
18521855
strbuf_addstr(value, "shallow wait-for-done");
18531856

18541857
if (data.allow_filter)
@@ -1860,13 +1863,8 @@ int upload_pack_advertise(struct repository *r,
18601863
if (data.allow_sideband_all)
18611864
strbuf_addstr(value, " sideband-all");
18621865

1863-
if (!repo_config_get_string(r,
1864-
"uploadpack.blobpackfileuri",
1865-
&str) &&
1866-
str) {
1866+
if (data.allow_packfile_uris)
18671867
strbuf_addstr(value, " packfile-uris");
1868-
free(str);
1869-
}
18701868
}
18711869

18721870
upload_pack_data_clear(&data);

0 commit comments

Comments
 (0)