From 4f58e18cba21c509f67998ad58e340136a6498c2 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Sep 2022 13:51:22 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@54299 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index fe378341aa..3ec8523a90 100644 --- a/src/wp-includes/functions.php +++ b/src/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; }