From 96026e2cd81965827c98f8d25783a06f7d8a6ad0 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 27 Nov 2023 18:52:53 -0800 Subject: [PATCH] fix(*) resolve a possible segfault in the FFI Creating the `rctx` can happen when no `wasm{}` block is configured (e.g. through the FFI in `init_worker`). For example, `set_host_properties_handlers()` might be called (wrong, and unlikely). Always assume `rctx` might not be created due to a `wasm{}` block, since the module is wider than Wasm support only. --- src/http/ngx_http_wasm_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/ngx_http_wasm_module.c b/src/http/ngx_http_wasm_module.c index 43ff937db..483c6528e 100644 --- a/src/http/ngx_http_wasm_module.c +++ b/src/http/ngx_http_wasm_module.c @@ -584,11 +584,11 @@ ngx_http_wasm_rctx(ngx_http_request_t *r, ngx_http_wasm_req_ctx_t **out) rctx->sock_buffer_reuse = loc->socket_buffer_reuse; rctx->pwm_lua_resolver = loc->pwm_lua_resolver != NGX_CONF_UNSET ? loc->pwm_lua_resolver - : wcf->pwm_lua_resolver; + : wcf ? wcf->pwm_lua_resolver : 0; } else { /* fake request */ - rctx->pwm_lua_resolver = wcf->pwm_lua_resolver; + rctx->pwm_lua_resolver = wcf ? wcf->pwm_lua_resolver : 0; } } #if (NGX_DEBUG)