Skip to content

Commit

Permalink
PHP 8.1: validate_file(): prevent "passing null to non-nullable" notice
Browse files Browse the repository at this point in the history
No input validation was done. Covered by existing `Tests_Functions::test_validate_file()` test (well, the `null` and string part is).

Error fixed: `preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated`

QUESTION: should we add tests for other scalar input types ?
  • Loading branch information
jrfnl committed Aug 11, 2021
1 parent 9b565f7 commit 3d7e9ce
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5661,6 +5661,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;
Expand Down

0 comments on commit 3d7e9ce

Please sign in to comment.