[php-src] Issue #11984: The chroot() doesn't get properly enabled/disabled when building SAPIs

From: Date: Tue, 15 Aug 2023 22:18:28 +0000
Subject: [php-src] Issue #11984: The chroot() doesn't get properly enabled/disabled when building SAPIs
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245194@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11984 Author: petk ### Description The following code: ```php <?php // check-chroot.php if(function_exists('chroot')) { echo 'chroot() exists'; } else { echo 'chroot() not available'; } ``` Resulted in this output when building like this: ```sh ./buildconf ./configure --disable-cli --disable-phpdbg --disable-cgi --enable-litespeed make -j$(nproc) ./sapi/litespeed/php check-chroot.php # chroot() not available (by current design this is ok) ``` And resulted in this output when building like this: ```sh ./buildconf ./configure --enable-cli --enable-phpdbg --enable-cgi --enable-litespeed make -j$(nproc) ./sapi/litespeed/php check-chroot.php # chroot() exists ``` But I expected this output instead: ```sh ./buildconf ./configure --enable-cli --enable-phpdbg --enable-cgi --enable-litespeed make -j$(nproc) ./sapi/litespeed/php check-chroot.php # chroot() not available ``` There is a check for relatively dangerous chroot() function in ext/standard/config.m4, where ENABLE_CHROOT_FUNC constant gets defined depending on the selected SAPI: ```m4 AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function]) ``` However, this is one of the parts that complicates the PHP build process. To get proper SAPIs, they all need to be build separately according to current design. I'm just noting this bug for possible future reference. I'm not sure yet how to fix this better. Because disabling chroot() function might seem more appropriate in the C code directly in the main/main.c (however, this is probably not good fix yet): ```diff --- a/main/main.c +++ b/main/main.c @@ -2223,6 +2223,10 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi } } + if (strcmp(sapi_module.name, "cli") != 0 && strcmp(sapi_module.name, "cgi-fcgi") != 0 && strcmp(sapi_module.name, "phpdbg") != 0 && strcmp(sapi_module.name, "embed") != 0) { + zend_disable_functions("chroot"); + } + /* disable certain classes and functions as requested by php.ini */ zend_disable_functions(INI_STR("disable_functions")); php_disable_classes(); ``` ### PHP Version PHP 8.1+ ### Operating System *nix

« previous php.bugs (#245194) next »