Commit fe88c67
authored
Initialize SWOOLE_G(cli) to avoid reading uninitialized global under threaded SAPIs (#6107)
php_swoole_init_globals() initializes every module global except `cli`,
relying on the storage being zero-initialized. That holds for the CLI and
single-threaded embed SAPIs, but not for threaded/embedded SAPIs such as
FrankenPHP: each worker thread's module globals are allocated per thread and
are not guaranteed to be zeroed before the ctor runs, so `cli` reads an
indeterminate value.
There, sapi_module.name is the host SAPI's own name (e.g. "frankenphp"), so
the cli/phpdbg/embed/micro check never sets `cli`. When the leftover value is
non-zero, PHP_RINIT_FUNCTION(swoole) passes its `if (!SWOOLE_G(cli)) return`
guard and runs the request path, which calls swoole_set_task_tmpdir() and
dereferences the (uninitialized) per-thread buffer, segfaulting on the first
request.
Explicitly default `cli` to false so the guard is reliable regardless of SAPI.1 parent 6015d3d commit fe88c67
1 file changed
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
| 387 | + | |
387 | 388 | | |
388 | 389 | | |
389 | 390 | | |
| |||
0 commit comments