diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Harden the lua filter failure paths
Diffstat (limited to 'source')
| -rw-r--r-- | source/filter.c | 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 9 insertions, 5 deletions
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; } |
