From 968d6e003b3f10ff3be444d6a7d81d97b7afc3a6 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Wed, 15 Jul 2026 14:01:34 -1000 Subject: Keep an overlong path out of the tab title `fmt()` aborts the request rather than truncate, so a very long path fed into a context-sensitive tab title took down page rendering. --- source/ui-shared.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/ui-shared.c b/source/ui-shared.c index 4084748..7cb8607 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -993,6 +993,17 @@ static const char *hc(const char *page) return strcmp(ctx.qry.page, page) ? NULL : "active"; } +/* Build a context-sensitive tab title such as "Commit history of ". + * fmt() aborts the request rather than truncate, so fall back to the plain + * label when the path is long enough to risk overflowing its buffer. */ +static const char *tab_title(const char *format, const char *generic, + const char *vpath) +{ + if (!vpath || !*vpath || strlen(vpath) > 256) + return generic; + return fmt(format, vpath); +} + static void cgit_print_path_crumbs(char *path) { char *old_path = ctx.qry.path; @@ -1114,19 +1125,19 @@ void cgit_print_pageheader(void) ctx.qry.oid, NULL); html("\n
  • "); cgit_log_link("log", - vp && *vp ? fmt("Commit history of %s", vp) : "Commit history", + tab_title("Commit history of %s", "Commit history", vp), hc("log"), ctx.qry.head, NULL, ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg, ctx.qry.follow); html("
  • \n
  • "); if (ctx.qry.page && !strcmp(ctx.qry.page, "blame")) cgit_blame_link("blame", - vp && *vp ? fmt("Line-by-line blame of %s", vp) : "Blame", + tab_title("Line-by-line blame of %s", "Blame", vp), hc("blame"), ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); else cgit_tree_link("tree", - vp && *vp ? fmt("Browse the tree at %s", vp) : "Browse the file tree", + tab_title("Browse the tree at %s", "Browse the file tree", vp), hc("tree"), ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); html("
  • \n
  • "); @@ -1134,7 +1145,7 @@ void cgit_print_pageheader(void) ctx.qry.head, ctx.qry.oid, ctx.qry.vpath); html("
  • \n
  • "); cgit_diff_link("diff", - vp && *vp ? fmt("Changes to %s", vp) : "Changes in the current commit", + tab_title("Changes to %s", "Changes in the current commit", vp), hc("diff"), ctx.qry.head, ctx.qry.oid, ctx.qry.oid2, ctx.qry.vpath); html("
  • \n"); -- cgit v2.8.0