From d7c22d29cfb6c813bf2318006f2cf399bccf1a2d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 16 Aug 2021 22:51:47 +0000 Subject: [PATCH] Code Modernization: Check the input type in `validate_file()`. This fixes a `preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated` notice on PHP 8.1. The behavior for `null` and `string` input is covered by the existing `Tests_Functions::test_validate_file()` test. Effect: Errors down by 238, assertions up by 1920, failures down by 1. Props jrf, hellofromTonya, SergeyBiryukov. See #53635. git-svn-id: https://develop.svn.wordpress.org/trunk@51625 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 33344f31532d3..7b01568ad42c0 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -5709,6 +5709,10 @@ function iis7_supports_permalinks() { * @return int 0 means nothing is wrong, greater than 0 means something was wrong. */ function validate_file( $file, $allowed_files = array() ) { + if ( ! is_scalar( $file ) || '' === $file ) { + return 0; + } + // `../` on its own is not allowed: if ( '../' === $file ) { return 1;