From 2fc008d6dea2456548825c973a5516b5cdfd9c8c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 28 Aug 2018 20:33:02 +0200 Subject: ui-shared: ban strcat() Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 To avoid compiler warnings from gcc 8.1.x we get the hard way. Signed-off-by: Christian Hesse --- ui-shared.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 739505a..b53c56d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1159,7 +1159,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, void cgit_set_title_from_path(const char *path) { - size_t path_len, path_index, path_last_end; + size_t path_len, path_index, path_last_end, line_len; char *new_title; if (!path) @@ -1176,14 +1176,18 @@ void cgit_set_title_from_path(const char *path) continue; } strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); - strcat(new_title, "\\"); + line_len = strlen(new_title); + new_title[line_len++] = '\\'; + new_title[line_len] = '\0'; path_last_end = path_index; } } if (path_last_end) strncat(new_title, path, path_last_end); - strcat(new_title, " - "); - strcat(new_title, ctx.page.title); + line_len = strlen(new_title); + memcpy(&new_title[line_len], " - ", 3); + new_title[line_len + 3] = '\0'; + strncat(new_title, ctx.page.title, sizeof(new_title) - strlen(new_title) - 1); ctx.page.title = new_title; } -- cgit v1.2.3-24-g4f1b From 898b9e19e0eacd67456ddcc91ff173055e1c0e99 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 21 Nov 2018 03:16:11 +0100 Subject: auth-filter: pass url with query string attached Otherwise redirections come out wrong. Signed-off-by: Jason A. Donenfeld --- ui-shared.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index b53c56d..7a4c726 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -68,15 +68,48 @@ char *cgit_hosturl(void) char *cgit_currenturl(void) { const char *root = cgit_rooturl(); - size_t len = strlen(root); if (!ctx.qry.url) return xstrdup(root); - if (len && root[len - 1] == '/') + if (root[0] && root[strlen(root) - 1] == '/') return fmtalloc("%s%s", root, ctx.qry.url); return fmtalloc("%s/%s", root, ctx.qry.url); } +char *cgit_currentfullurl(void) +{ + const char *root = cgit_rooturl(); + const char *orig_query = ctx.env.query_string ? ctx.env.query_string : ""; + size_t len = strlen(orig_query); + char *query = xmalloc(len + 2), *start_url, *ret; + + /* Remove all url=... parts from query string */ + memcpy(query + 1, orig_query, len + 1); + query[0] = '?'; + start_url = query; + while ((start_url = strstr(start_url, "url=")) != NULL) { + if (start_url[-1] == '?' || start_url[-1] == '&') { + const char *end_url = strchr(start_url, '&'); + if (end_url) + memmove(start_url, end_url + 1, strlen(end_url)); + else + start_url[0] = '\0'; + } else + ++start_url; + } + if (!query[1]) + query[0] = '\0'; + + if (!ctx.qry.url) + ret = fmtalloc("%s%s", root, query); + else if (root[0] && root[strlen(root) - 1] == '/') + ret = fmtalloc("%s%s%s", root, ctx.qry.url, query); + else + ret = fmtalloc("%s/%s%s", root, ctx.qry.url, query); + free(query); + return ret; +} + const char *cgit_rooturl(void) { if (ctx.cfg.virtual_root) -- cgit v1.2.3-24-g4f1b From e23f63461f17aeb770d47d9c3134414e549d1f0e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 2 Jan 2019 07:52:12 +0100 Subject: ui-shared: fix broken sizeof in title setting and rewrite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old algorithm was totally incorrect. While we're at it, use « instead of \, since it makes more sense. Signed-off-by: Jason A. Donenfeld --- ui-shared.c | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'ui-shared.c') diff --git a/ui-shared.c b/ui-shared.c index 7a4c726..d27a5fd 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1192,35 +1192,17 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, void cgit_set_title_from_path(const char *path) { - size_t path_len, path_index, path_last_end, line_len; - char *new_title; + struct strbuf sb = STRBUF_INIT; + const char *slash, *last_slash; if (!path) return; - path_len = strlen(path); - new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); - new_title[0] = '\0'; - - for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { - if (path[path_index] == '/') { - if (path_index == path_len - 1) { - path_last_end = path_index - 1; - continue; - } - strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); - line_len = strlen(new_title); - new_title[line_len++] = '\\'; - new_title[line_len] = '\0'; - path_last_end = path_index; - } + for (last_slash = path + strlen(path); (slash = memrchr(path, '/', last_slash - path)) != NULL; last_slash = slash) { + strbuf_add(&sb, slash + 1, last_slash - slash - 1); + strbuf_addstr(&sb, " \xc2\xab "); } - if (path_last_end) - strncat(new_title, path, path_last_end); - - line_len = strlen(new_title); - memcpy(&new_title[line_len], " - ", 3); - new_title[line_len + 3] = '\0'; - strncat(new_title, ctx.page.title, sizeof(new_title) - strlen(new_title) - 1); - ctx.page.title = new_title; + strbuf_add(&sb, path, last_slash - path); + strbuf_addf(&sb, " - %s", ctx.page.title); + ctx.page.title = strbuf_detach(&sb, NULL); } -- cgit v1.2.3-24-g4f1b From 54c407a74a35d4ee9ffae94cc5bc9096c9f7f54a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 20 May 2019 21:45:12 +0200 Subject: ui-shared: restrict to 15 levels 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 --- ui-shared.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui-shared.c') 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; } -- cgit v1.2.3-24-g4f1b