From 61d3eafe98847b9a76ddc04fe7a4f63f341961a4 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 6 Sep 2026 21:40:19 -1000 Subject: Harden the lua filter failure paths --- source/filter.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source/filter.c') diff --git a/source/filter.c b/source/filter.c index f5f971c..a7efe56 100644 --- a/source/filter.c +++ b/source/filter.c @@ -173,6 +173,11 @@ static inline void unhook_write(void) static NORETURN void die_lua_error(struct lua_filter *filter) { + // The error page goes out through stdout, which may still be hooked + // to the very filter that failed, so the hook comes off first or the + // page would be fed back into the broken filter. + if (filter_write) + unhook_write(); die("Lua error in %s: %s", filter->script_file, lua_tostring(filter->lua_state, -1)); } @@ -336,11 +341,10 @@ static void cleanup_lua_filter(struct cgit_filter *base) { struct lua_filter *filter = (struct lua_filter *)base; - if (!filter->lua_state) - return; - - lua_close(filter->lua_state); - filter->lua_state = NULL; + if (filter->lua_state) { + lua_close(filter->lua_state); + filter->lua_state = NULL; + } free(filter->script_file); filter->script_file = NULL; } -- cgit v2.8.0