Skip to content

Commit 3d6a89e

Browse files
authored
Integrate the security fix release 2.55.0.vfs.0.8 (#978)
See https://github.com/microsoft/git/releases/tag/v2.55.0.vfs.0.8.
2 parents f7ebbb5 + de48cba commit 3d6a89e

7 files changed

Lines changed: 114 additions & 8 deletions

File tree

bundle-uri.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "remote.h"
1616
#include "trace2.h"
1717
#include "odb.h"
18+
#include "transport.h"
19+
#include "url.h"
1820

1921
static struct {
2022
enum bundle_list_heuristic heuristic;
@@ -890,11 +892,59 @@ int fetch_bundle_uri(struct repository *r, const char *uri,
890892
return result;
891893
}
892894

895+
/* protocol of 'uri', or "file" if it has none (bare/UNC/relative path) */
896+
static void bundle_uri_protocol(const char *uri, struct strbuf *out)
897+
{
898+
const char *p = uri;
899+
900+
while (is_urlschemechar(p == uri, *p))
901+
p++;
902+
strbuf_reset(out);
903+
if (p > uri && starts_with(p, "://"))
904+
strbuf_add(out, uri, p - uri);
905+
else
906+
strbuf_addstr(out, "file");
907+
}
908+
909+
/* Drop advertised URIs whose protocol is not allowed (see protocol.*.allow). */
910+
static void sanitize_bundle_list(struct bundle_list *list)
911+
{
912+
struct remote_bundle_info **skipped;
913+
size_t nr = 0, i;
914+
struct remote_bundle_info *info;
915+
struct hashmap_iter iter;
916+
struct strbuf proto = STRBUF_INIT;
917+
918+
ALLOC_ARRAY(skipped, hashmap_get_size(&list->bundles));
919+
hashmap_for_each_entry(&list->bundles, &iter, info, ent) {
920+
if (!info->uri)
921+
continue;
922+
bundle_uri_protocol(info->uri, &proto);
923+
/* advertised URIs are not user-provided */
924+
if (!is_transport_allowed(proto.buf, 0)) {
925+
warning(_("skipping bundle URI '%s': protocol '%s' "
926+
"is not allowed"), info->uri, proto.buf);
927+
skipped[nr++] = info;
928+
}
929+
}
930+
strbuf_release(&proto);
931+
932+
for (i = 0; i < nr; i++) {
933+
hashmap_remove(&list->bundles, &skipped[i]->ent, NULL);
934+
clear_remote_bundle_info(skipped[i], NULL);
935+
free(skipped[i]);
936+
}
937+
938+
free(skipped);
939+
}
940+
893941
int fetch_bundle_list(struct repository *r, struct bundle_list *list)
894942
{
895943
int result;
896944
struct bundle_list global_list;
897945

946+
sanitize_bundle_list(list);
947+
898948
/*
899949
* If the creationToken heuristic is used, then the URIs
900950
* advertised by 'list' are not nested lists and instead

odb/source-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int odb_source_files_freshen_object(struct odb_source *source,
164164
}
165165

166166
static int odb_source_files_write_object(struct odb_source *source,
167-
const void *buf, unsigned long len,
167+
const void *buf, size_t len,
168168
enum object_type type,
169169
struct object_id *oid,
170170
struct object_id *compat_oid,

odb/source-inmemory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static int odb_source_inmemory_count_objects(struct odb_source *source,
227227
}
228228

229229
static int odb_source_inmemory_write_object(struct odb_source *source,
230-
const void *buf, unsigned long len,
230+
const void *buf, size_t len,
231231
enum object_type type,
232232
struct object_id *oid,
233233
struct object_id *compat_oid UNUSED,

odb/source-loose.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static int odb_source_loose_freshen_object(struct odb_source *source,
595595
}
596596

597597
static int odb_source_loose_write_object(struct odb_source *source,
598-
const void *buf, unsigned long len,
598+
const void *buf, size_t len,
599599
enum object_type type, struct object_id *oid,
600600
struct object_id *compat_oid_in,
601601
enum odb_write_object_flags flags)

odb/source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct odb_source {
200200
* return 0 on success, a negative error code otherwise.
201201
*/
202202
int (*write_object)(struct odb_source *source,
203-
const void *buf, unsigned long len,
203+
const void *buf, size_t len,
204204
enum object_type type,
205205
struct object_id *oid,
206206
struct object_id *compat_oid,

t/lib-bundle-uri-protocol.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,59 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
214214
>actual &&
215215
test_cmp_config_output expect actual
216216
'
217+
218+
# Advertised bundle URIs are subject to protocol.*.allow; "file" (and bare or
219+
# UNC paths) is denied by default, so such a URI must be skipped, not fetched.
220+
advertise_uri () {
221+
test_config -C "$BUNDLE_URI_PARENT" bundle.version 1 &&
222+
test_config -C "$BUNDLE_URI_PARENT" bundle.mode all &&
223+
test_config -C "$BUNDLE_URI_PARENT" bundle.payload.uri "$1"
224+
}
225+
226+
ignores_advertised_uri () {
227+
rm -rf victim &&
228+
advertise_uri "$1" &&
229+
git -c transfer.bundleURI=true -c protocol.version=2 \
230+
clone "$BUNDLE_URI_REPO_URI" victim &&
231+
git -C victim for-each-ref refs/bundles/ >refs &&
232+
test_must_be_empty refs
233+
}
234+
235+
test_expect_success "create bundle to advertise" '
236+
git -C "$BUNDLE_URI_PARENT" bundle create "$PWD/payload.bundle" main
237+
'
238+
239+
test_expect_success "ignore non-HTTP(S) bundle URI with $BUNDLE_URI_PROTOCOL://" '
240+
ignores_advertised_uri "$PWD/payload.bundle" &&
241+
ignores_advertised_uri "file://$PWD/payload.bundle"
242+
'
243+
244+
test_expect_success "protocol.file.allow=always honors file bundle URI with $BUNDLE_URI_PROTOCOL://" '
245+
rm -rf victim &&
246+
advertise_uri "$PWD/payload.bundle" &&
247+
git -c transfer.bundleURI=true -c protocol.version=2 \
248+
-c protocol.file.allow=always \
249+
clone "$BUNDLE_URI_REPO_URI" victim &&
250+
git -C victim rev-parse --verify refs/bundles/heads/main
251+
'
252+
253+
# same path via a UNC administrative share (cf. t5580-unc-paths.sh)
254+
if test_have_prereq CYGWIN
255+
then
256+
UNCPATH="$(cygpath -aw .)"
257+
elif test_have_prereq MINGW
258+
then
259+
UNCPATH="$(pwd)"
260+
fi
261+
case "$UNCPATH" in
262+
[A-Za-z]:*)
263+
WITHOUTDRIVE="${UNCPATH#?:}"
264+
UNCPATH="//localhost/${UNCPATH%%:*}\$$WITHOUTDRIVE"
265+
test -d "$UNCPATH" && test_set_prereq ADMIN_UNC
266+
;;
267+
esac
268+
269+
test_expect_success ADMIN_UNC "ignore UNC bundle URI with $BUNDLE_URI_PROTOCOL://" '
270+
ignores_advertised_uri "$UNCPATH/payload.bundle" &&
271+
ignores_advertised_uri "file://$UNCPATH/payload.bundle"
272+
'

t/t1007-hash-object.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,23 +261,23 @@ test_expect_success '--stdin outside of repository (uses default hash)' '
261261
test_cmp expect actual
262262
'
263263

264-
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
264+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
265265
'files over 4GB hash literally' '
266266
test-tool genzeros $((5*1024*1024*1024)) >big &&
267267
test_oid large5GB >expect &&
268268
git hash-object --stdin --literally <big >actual &&
269269
test_cmp expect actual
270270
'
271271

272-
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
272+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
273273
'files over 4GB hash correctly via --stdin' '
274274
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
275275
test_oid large5GB >expect &&
276276
git hash-object --stdin <big >actual &&
277277
test_cmp expect actual
278278
'
279279

280-
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
280+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
281281
'files over 4GB hash correctly' '
282282
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
283283
test_oid large5GB >expect &&
@@ -287,7 +287,7 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
287287

288288
# This clean filter does nothing, other than excercising the interface.
289289
# We ensure that cleaning doesn't mangle large files on 64-bit Windows.
290-
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
290+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
291291
'hash filtered files over 4GB correctly' '
292292
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
293293
test_oid large5GB >expect &&

0 commit comments

Comments
 (0)