Skip to content

Commit 50a3c54

Browse files
committed
Enable chroot() based on the SAPI type
CLI-based SAPIs (cgi, cli, embed, phpdbg) (those with the PHP_SAPI_CLI CMake property), have now chroot() PHP function enabled. Other SAPIs do not to prevent user-level misuse.
1 parent 5bb8b10 commit 50a3c54

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

cmake/cmake/ConfigureChecks.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ include(PHP/CheckAVX512)
256256
################################################################################
257257

258258
check_symbol_exists(alphasort "dirent.h" HAVE_ALPHASORT)
259-
check_symbol_exists(chroot "unistd.h" HAVE_CHROOT)
260259
check_symbol_exists(explicit_memset "string.h" HAVE_EXPLICIT_MEMSET)
261260
check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
262261
# The fdatasync declaration on macOS is missing in headers, yet is in C library.

cmake/ext/standard/CMakeLists.txt

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ target_sources(
6868
array.c
6969
assert.c
7070
base64.c
71-
basic_functions.c
7271
basic_functions.stub.php
7372
browscap.c
7473
crc32.c
7574
credits.c
7675
crypt.c
7776
css.c
7877
datetime.c
79-
dir.c
8078
dir.stub.php
8179
dl.c
8280
dl.stub.php
@@ -522,8 +520,55 @@ block()
522520
add_dependencies(php_standard php_standard_credits)
523521
endblock()
524522

525-
# TODO: Check whether to enable the chroot() function by checking which SAPI is
526-
# being built.
527-
set(ENABLE_CHROOT_FUNC TRUE)
523+
################################################################################
524+
# Add chroot() based on the SAPI type. It should be enabled only for the
525+
# CLI-based SAPIs. This enables building all SAPIs in a single build invocation.
526+
# Here, a build-time solution is integrated, although this would be better
527+
# resolved as mentioned in the issue report.
528+
# See: https://github.com/php/php-src/issues/11984
529+
################################################################################
530+
531+
check_symbol_exists(chroot "unistd.h" HAVE_CHROOT)
532+
533+
add_library(php_standard_functions_cli OBJECT)
534+
add_library(php_standard_functions OBJECT)
535+
536+
target_sources(php_standard_functions_cli PRIVATE basic_functions.c dir.c)
537+
target_sources(php_standard_functions PRIVATE basic_functions.c dir.c)
538+
539+
target_compile_definitions(php_standard_functions_cli PRIVATE )
540+
541+
target_include_directories(
542+
php_standard_functions_cli
543+
PRIVATE
544+
$<TARGET_PROPERTY:php_standard,INCLUDE_DIRECTORIES>
545+
)
546+
target_include_directories(
547+
php_standard_functions
548+
PRIVATE
549+
$<TARGET_PROPERTY:php_standard,INCLUDE_DIRECTORIES>
550+
)
551+
target_compile_definitions(
552+
php_standard_functions_cli
553+
PRIVATE
554+
$<TARGET_PROPERTY:php_standard,COMPILE_DEFINITIONS>
555+
ENABLE_CHROOT_FUNC
556+
)
557+
target_compile_definitions(
558+
php_standard_functions
559+
PRIVATE $<TARGET_PROPERTY:php_standard,COMPILE_DEFINITIONS>
560+
)
561+
target_link_libraries(
562+
php_standard_functions_cli
563+
PRIVATE $<TARGET_PROPERTY:php_standard,LINK_LIBRARIES>
564+
)
565+
target_link_libraries(
566+
php_standard_functions
567+
PRIVATE $<TARGET_PROPERTY:php_standard,LINK_LIBRARIES>
568+
)
569+
570+
################################################################################
571+
# Configuration header
572+
################################################################################
528573

529574
configure_file(config.cmake.h.in config.h)

cmake/ext/standard/config.cmake.h.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
/* Define to 1 if crypt_r uses struct crypt_data. */
88
#cmakedefine CRYPT_R_STRUCT_CRYPT_DATA 1
99

10-
/* Define to 1 to enable the 'chroot' function. */
11-
#cmakedefine ENABLE_CHROOT_FUNC 1
12-
1310
/* Define to 1 when aarch64 CRC32 API is available. */
1411
#cmakedefine HAVE_AARCH64_CRC32 1
1512

1613
/* Define to 1 if the system has the 'libargon2' library. */
1714
#cmakedefine HAVE_ARGON2LIB 1
1815

16+
/* Define to 1 if you have the 'chroot' function. */
17+
#cmakedefine HAVE_CHROOT 1
18+
1919
/* Define to 1 if you have the 'crypt' function. */
2020
#cmakedefine HAVE_CRYPT 1
2121

cmake/main/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ target_sources(
189189
$<$<AND:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>,$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,STATIC_LIBRARY>>:$<TARGET_OBJECTS:Zend::Zend>>
190190

191191
$<$<TARGET_EXISTS:PHP::windows>:$<TARGET_OBJECTS:PHP::windows>>
192+
193+
# ext/standard functions objects based on the SAPI type.
194+
$<IF:$<BOOL:$<TARGET_PROPERTY:PHP_SAPI_CLI>>,$<TARGET_OBJECTS:php_standard_functions_cli>,$<TARGET_OBJECTS:php_standard_functions>>
192195
)
193196

194197
################################################################################

cmake/main/php_config.cmake.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@
9191
/* Define to 1 if PHP has the <main/build-defs.h> header file. */
9292
#cmakedefine HAVE_BUILD_DEFS_H 1
9393

94-
/* Define to 1 if you have the 'chroot' function. */
95-
#cmakedefine HAVE_CHROOT 1
96-
9794
/* Define to 1 if you have the 'copy_file_range' function. */
9895
#cmakedefine HAVE_COPY_FILE_RANGE 1
9996

0 commit comments

Comments
 (0)