From 3d245c574e4c36aed7fb8ca174807f9b828a4dbc Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Sep 2022 13:53:13 +0000 Subject: [PATCH] General: Correct the fallback logic in `apache_mod_loaded()`. If the `apache_get_modules()` function is redeclared to return an empty array, `apache_mod_loaded()` would assume that no Apache modules are installed and activated, which may not be correct. This commit improves the logic by using pre-existing `phpinfo()` fallback to check for loaded modules in that case. Includes replacing a hardcoded number passed as a flag to `phpinfo()` with the `INFO_MODULES` predefined constant for clarity. Follow-up to [7441], [7508], [29330]. Props engahmeds3ed, audrasjb, Clorith, SergeyBiryukov. Fixes #56010. Built from https://develop.svn.wordpress.org/trunk@54299 git-svn-id: http://core.svn.wordpress.org/trunk@53858 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 21 +++++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index fe378341aa..3ec8523a90 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -5888,15 +5888,24 @@ function apache_mod_loaded( $mod, $default = false ) { return false; } + $loaded_mods = array(); + if ( function_exists( 'apache_get_modules' ) ) { - $mods = apache_get_modules(); - if ( in_array( $mod, $mods, true ) ) { + $loaded_mods = apache_get_modules(); + + if ( in_array( $mod, $loaded_mods, true ) ) { return true; } - } elseif ( function_exists( 'phpinfo' ) && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) ) { - ob_start(); - phpinfo( 8 ); - $phpinfo = ob_get_clean(); + } + + if ( empty( $loaded_mods ) + && function_exists( 'phpinfo' ) + && false === strpos( ini_get( 'disable_functions' ), 'phpinfo' ) + ) { + ob_start(); + phpinfo( INFO_MODULES ); + $phpinfo = ob_get_clean(); + if ( false !== strpos( $phpinfo, $mod ) ) { return true; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 6adeed4841..d5d90c40cf 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta1-54298'; +$wp_version = '6.1-beta1-54299'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.