amishmm / php-pam

This extension provides PAM (Pluggable Authentication Modules) integration for PHP
Other
10 stars 5 forks source link

Update TSRMLS_CACHE in RINIT_FUNCTION and MINIT_FUNCTION #12

Closed dummyunit closed 2 years ago

dummyunit commented 2 years ago

When extension is compiled in ZTS mode as a dynamic library both the extension and the php executable have their own copy of global thread-local variable _tsrm_ls_cache (a.k.a TSRMLS_CACHE). When extension is compiled with define ZEND_ENABLE_STATIC_TSRMLS_CACHE (which is non-configurable and enabled by default in the build system) the extension uses that variable directly instead of going through tsrm_get_ls_cache() function, so it is important that both copies stay synchronized. If they are not kept in sync then extension may use it own copy which is only initialized to NULL and crash on accessing its module global.

This synchronization should be done on each request as different requests may be handled in different (new) threads (e.g. in Apache's mod_php when a threaded MPM is used). We also do this in MINIT_FUNCTION just in case.

Fixes: #11

adb014 commented 2 years ago

Yes that fixed the segfault