Tuesday, August 02, 2022

www/nginx: fix crash when init_worker_by_lua is used

Currently if you load the lua module and use init_worker_by_lua, worker
processes crash on startup. I found a fix for this in lua-nginx-module git.
As far as I can tell, newer versions of the lua module only work with luajit,
so we can't just update it to a version with this fix.


Index: Makefile
===================================================================
RCS file: /cvs/ports/www/nginx/Makefile,v
retrieving revision 1.163
diff -u -p -u -p -r1.163 Makefile
--- Makefile 30 May 2022 08:17:34 -0000 1.163
+++ Makefile 2 Aug 2022 08:04:47 -0000
@@ -19,6 +19,8 @@ VERSION= 1.22.0
DISTNAME= nginx-${VERSION}
CATEGORIES= www

+REVISION-lua= 0
+
VERSION-rtmp= 1.2.1

PKGNAME-main= ${DISTNAME}
Index: patches/patch-lua-nginx-module_src_ngx_http_lua_initworkerby_c
===================================================================
RCS file: patches/patch-lua-nginx-module_src_ngx_http_lua_initworkerby_c
diff -N patches/patch-lua-nginx-module_src_ngx_http_lua_initworkerby_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-lua-nginx-module_src_ngx_http_lua_initworkerby_c 2 Aug 2022 08:04:47 -0000
@@ -0,0 +1,25 @@
+upstream commit e94f2e5d64daa45ff396e262d8dab8e56f5f10e0
+fixing crash when init_worker_by_lua is used.
+
+Index: lua-nginx-module/src/ngx_http_lua_initworkerby.c
+--- lua-nginx-module/src/ngx_http_lua_initworkerby.c.orig
++++ lua-nginx-module/src/ngx_http_lua_initworkerby.c
+@@ -25,6 +25,7 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
+ void *cur, *prev;
+ ngx_uint_t i;
+ ngx_conf_t conf;
++ ngx_conf_file_t cf_file;
+ ngx_cycle_t *fake_cycle;
+ ngx_module_t **modules;
+ ngx_open_file_t *file, *ofile;
+@@ -142,6 +143,10 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
+ conf.cycle = fake_cycle;
+ conf.pool = fake_cycle->pool;
+ conf.log = cycle->log;
++
++ ngx_memzero(&cf_file, sizeof(cf_file));
++ cf_file.file.name = cycle->conf_file;
++ conf.conf_file = &cf_file;
+
+ http_ctx.loc_conf = ngx_pcalloc(conf.pool,
+ sizeof(void *) * ngx_http_max_module);

No comments:

Post a Comment