From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason at zx2c4.com (Jason A. Donenfeld) Date: Mon, 20 May 2019 21:55:06 +0200 Subject: [PATCH] ui-shared: restrict to 15 levels In-Reply-To: References: Message-ID: <20190520195506.16860-1-Jason@zx2c4.com> Perhaps a more ideal version of this would be to not print breadcrumbs at all for paths that don't exist in the given repo at the given oid. Signed-off-by: Jason A. Donenfeld Reported-by: Fydor Wire Snark --- I've committed this, and it works. But if anyone would like to give the implementation a stab, I think a better approach might be simply skipping printing of breadcrumbs in cases where the path doesn't exist in the repo. This way we're not limited to some reasonable constant such as 15. ui-shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui-shared.c b/ui-shared.c index d27a5fd..d2358f2 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -945,12 +945,13 @@ static void cgit_print_path_crumbs(char *path) { char *old_path = ctx.qry.path; char *p = path, *q, *end = path + strlen(path); + int levels = 0; ctx.qry.path = NULL; cgit_self_link("root", NULL, NULL); ctx.qry.path = p = path; while (p < end) { - if (!(q = strchr(p, '/'))) + if (!(q = strchr(p, '/')) || levels > 15) q = end; *q = '\0'; html_txt("/"); @@ -958,6 +959,7 @@ static void cgit_print_path_crumbs(char *path) if (q < end) *q = '/'; p = q + 1; + ++levels; } ctx.qry.path = old_path; } -- 2.21.0