bundle-uri: limit recursion depth for bundle lists
The next change will start allowing us to parse bundle lists that are downloaded from a provided bundle URI. Those lists might point to other lists, which could proceed to an arbitrary depth (and even create cycles). Restructure fetch_bundle_uri() to have an internal version that has a recursion depth. Compare that to a new max_bundle_uri_depth constant that is twice as high as we expect this depth to be for any legitimate use of bundle list linking. We can consider making max_bundle_uri_depth a configurable value if there is demonstrated value in the future. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Oct 12, 2022 at 12:52 UTC
20c1e2a68bfcb85dd919c92a82c129cee215c23a
1 file changed
+20
-1
bundle-uri.c
+20
-1
@@ -334,11 +334,25 @@ static int unbundle_from_file(struct repository *r, const char *file)
334
return result;
335
}
336
337
-int fetch_bundle_uri(struct repository *r, const char *uri)
337
+/**
338
+ * This limits the recursion on fetch_bundle_uri_internal() when following
339
+ * bundle lists.
340
+ */
341
+static int max_bundle_uri_depth = 4;
342
+
343
+static int fetch_bundle_uri_internal(struct repository *r,
344
+ const char *uri,
345
+ int depth)
346
{
347
int result = 0;
348
char *filename;
349
350
+ if (depth >= max_bundle_uri_depth) {
351
+ warning(_("exceeded bundle URI recursion limit (%d)"),
352
+ max_bundle_uri_depth);
353
+ return -1;
354
+ }
355
+
356
if (!(filename = find_temp_filename())) {
357
result = -1;
358
goto cleanup;
@@ -366,6 +380,11 @@ cleanup:
380
return result;
381
}
382
383
+int fetch_bundle_uri(struct repository *r, const char *uri)
384
+{
385
+ return fetch_bundle_uri_internal(r, uri, 0);
386
+}
387
+
388
/**
389
* General API for {transport,connect}.c etc.
390
*/