[PATCH] bundle-uri.c: Fix double increment in depth

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A bundle URI can serve a gitformat-bundle(5) or a bundle list. This
plain text file is in the Git config format containing other bundle
URIs. To avoid these bundle lists to nest too deep, we've set a limit
with `max_bundle_uri_depth`. Although, when walk through the tree of
bundles, the current depth is incremented in download_bundle_list() and
then calls download_bundle_to_file(), which also increments the depth.
Remove the increment in download_bundle_to_file().

Signed-off-by: Toon Claes <toon@xxxxxxxxx>
---
 bundle-uri.c                |  2 +-
 t/t5558-clone-bundle-uri.sh | 62 +++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/bundle-uri.c b/bundle-uri.c
index 91b3319a5c..7b1a711919 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -436,7 +436,7 @@ static int download_bundle_to_file(struct remote_bundle_info *bundle, void *data
 	if (ctx->mode == BUNDLE_MODE_ANY && ctx->count)
 		return 0;

-	res = fetch_bundle_uri_internal(ctx->r, bundle, ctx->depth + 1, ctx->list);
+	res = fetch_bundle_uri_internal(ctx->r, bundle, ctx->depth, ctx->list);

 	/*
 	 * Only increment count if the download succeeded. If our mode is
diff --git a/t/t5558-clone-bundle-uri.sh b/t/t5558-clone-bundle-uri.sh
index 1ca5f745e7..f3a8494297 100755
--- a/t/t5558-clone-bundle-uri.sh
+++ b/t/t5558-clone-bundle-uri.sh
@@ -259,6 +259,68 @@ test_expect_success 'clone bundle list (file, any mode, all failures)' '
 	! grep "refs/bundles/" refs
 '

+test_expect_success 'clone bundle list (file, above max depth)' '
+	cat >bundle-list-1 <<-EOF &&
+	[bundle]
+		version = 1
+		mode = any
+
+	[bundle "bundle-list-2"]
+		uri = file://$(pwd)/bundle-list-2
+	EOF
+
+	cat >bundle-list-2 <<-EOF &&
+	[bundle]
+		version = 1
+		mode = any
+
+	[bundle "bundle-list-3"]
+		uri = file://$(pwd)/bundle-list-3
+	EOF
+
+	cat >bundle-list-3 <<-EOF &&
+	[bundle]
+		version = 1
+		mode = any
+
+	[bundle "bundle-list-4"]
+		uri = file://$(pwd)/bundle-list-4
+	EOF
+
+	cat >bundle-list-4 <<-EOF &&
+	[bundle]
+		version = 1
+		mode = any
+
+	[bundle "bundle-0"]
+		uri = file://$(pwd)/clone-from/bundle-0.bundle
+	EOF
+
+	git clone --bundle-uri="file://$(pwd)/bundle-list-1" \
+		clone-from clone-too-deep 2>err &&
+	! grep "fatal" err &&
+	grep "warning: exceeded bundle URI recursion limit" err &&
+
+	git -C clone-from for-each-ref --format="%(objectname)" >oids &&
+	git -C clone-too-deep cat-file --batch-check <oids &&
+
+	git -C clone-too-deep for-each-ref --format="%(refname)" >refs &&
+	! grep "refs/bundles/" refs
+'
+
+test_expect_success 'clone bundle list (file, below max depth)' '
+	git clone --bundle-uri="file://$(pwd)/bundle-list-2" \
+		clone-from clone-max-depth 2>err &&
+	! grep "fatal" err &&
+	! grep "warning: exceeded bundle URI recursion limit" err &&
+
+	git -C clone-from for-each-ref --format="%(objectname)" >oids &&
+	git -C clone-max-depth cat-file --batch-check <oids &&
+
+	git -C clone-max-depth for-each-ref --format="%(refname)" >refs &&
+	! grep "refs/bundles/" refs
+'
+
 #########################################################################
 # HTTP tests begin here

--
2.45.0




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux