Skip to content

Commit 20c1e2a

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 738e524 commit 20c1e2a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

bundle-uri.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,25 @@ static int unbundle_from_file(struct repository *r, const char *file)
334334
return result;
335335
}
336336

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)
338346
{
339347
int result = 0;
340348
char *filename;
341349

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+
342356
if (!(filename = find_temp_filename())) {
343357
result = -1;
344358
goto cleanup;
@@ -366,6 +380,11 @@ int fetch_bundle_uri(struct repository *r, const char *uri)
366380
return result;
367381
}
368382

383+
int fetch_bundle_uri(struct repository *r, const char *uri)
384+
{
385+
return fetch_bundle_uri_internal(r, uri, 0);
386+
}
387+
369388
/**
370389
* General API for {transport,connect}.c etc.
371390
*/

0 commit comments

Comments
 (0)