We don't get any return value from compile_grep_patterns calling compile_regexp_failed, causing the default die routine to print to stderr and then for cgit to exit ungracefully.
Instead override the default die routine to show a normal error page. Perhaps compile_grep_patterns ought to change upstream to return an error. But this commit here will handle future issues as well, so perhaps not a bad idea to do anyway. Link: https://lists.zx2c4.com/pipermail/cgit/2026-March/004982.html Link: https://lists.zx2c4.com/pipermail/cgit/2026-March/004983.html Reported-by: Adrian C. <[email protected]> Reported-by: Aiden Woodruff <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> --- cgit.c | 7 +++++++ ui-shared.c | 9 +++++++-- ui-shared.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cgit.c b/cgit.c index c91897a..c4dc94c 100644 --- a/cgit.c +++ b/cgit.c @@ -1058,6 +1058,12 @@ static int calc_ttl(void) return ctx.cfg.cache_repo_ttl; } +static NORETURN void cgit_die_routine(const char *msg, va_list params) +{ + cgit_vprint_error_page(400, "Bad request", msg, params); + exit(0); +} + int cmd_main(int argc, const char **argv) { const char *path; @@ -1065,6 +1071,7 @@ int cmd_main(int argc, const char **argv) cgit_init_filters(); atexit(cgit_cleanup_filters); + set_die_routine(cgit_die_routine); prepare_context(); cgit_repolist.length = 0; diff --git a/ui-shared.c b/ui-shared.c index 219b830..df52a9b 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -889,13 +889,18 @@ void cgit_print_docend(void) void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) { va_list ap; + va_start(ap, fmt); + cgit_vprint_error_page(code, msg, fmt, ap); + va_end(ap); +} + +void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap) +{ ctx.page.expires = ctx.cfg.cache_dynamic_ttl; ctx.page.status = code; ctx.page.statusmsg = msg; cgit_print_layout_start(); - va_start(ap, fmt); cgit_vprint_error(fmt, ap); - va_end(ap); cgit_print_layout_end(); } diff --git a/ui-shared.h b/ui-shared.h index f12fa99..2a3a7f5 100644 --- a/ui-shared.h +++ b/ui-shared.h @@ -73,6 +73,7 @@ extern void cgit_print_docstart(void); extern void cgit_print_docend(void); __attribute__((format (printf,3,4))) extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...); +extern void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap); extern void cgit_print_pageheader(void); extern void cgit_print_filemode(unsigned short mode); extern void cgit_compose_snapshot_prefix(struct strbuf *filename, -- 2.53.0
