summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_php_sapi.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2021-11-25 19:58:54 +0300
committerValentin Bartenev <vbart@nginx.com>2021-11-25 19:58:54 +0300
commitf8237911d723ed1c8db0e4e5b75e1126b94f798a (patch)
treebb26ca99bfabd562e6b54ea41894a3865d51c684 /src/nxt_php_sapi.c
parent42e2105282cbfaf898d3f9b0eac7b288cc24cba1 (diff)
downloadunit-f8237911d723ed1c8db0e4e5b75e1126b94f798a.tar.gz
unit-f8237911d723ed1c8db0e4e5b75e1126b94f798a.tar.bz2
PHP: fixed crash when calling module functions in OPcache preload.
In PHP, custom fastcgi_finish_request() and overloaded chdir() functions can be invoked by an OPcache preloading script (it runs when php_module_startup() is called in the app process setup handler). In this case, there was no runtime context set so trying to access it caused a segmentation fault. This closes #602 issue on GitHub.
Diffstat (limited to '')
-rw-r--r--src/nxt_php_sapi.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c
index ea5f5581..68ef07eb 100644
--- a/src/nxt_php_sapi.c
+++ b/src/nxt_php_sapi.c
@@ -204,7 +204,10 @@ ZEND_NAMED_FUNCTION(nxt_php_chdir)
nxt_php_run_ctx_t *ctx;
ctx = SG(server_context);
- ctx->chdir = 1;
+
+ if (nxt_fast_path(ctx != NULL)) {
+ ctx->chdir = 1;
+ }
nxt_php_chdir_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
@@ -225,7 +228,7 @@ PHP_FUNCTION(fastcgi_finish_request)
ctx = SG(server_context);
- if (nxt_slow_path(ctx->req == NULL)) {
+ if (nxt_slow_path(ctx == NULL || ctx->req == NULL)) {
RETURN_FALSE;
}