Make WordPress Core


Ignore:
Timestamp:
10/18/2024 11:35:02 PM (2 years ago)
Author:
azaozz
Message:

Upgrade/Install: Return WP_Error when source files cannot be found.

Fixes a fatal error in array_keys() (PHP 8.0+) as $wp_filesystem->dirlist() will return false when the source directory doesn't exist or becomes unreadable for some reason.

Props: verygoode, lifelightweb, da5f656f, costdev, afragen, azaozz
Fixes #61114

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r59039 r59257  
    205205                $this->strings['incompatible_archive'] = __( 'The package could not be installed.' );
    206206                $this->strings['files_not_writable']   = __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' );
     207                $this->strings['dir_not_readable']     = __( 'A directory could not be read.' );
    207208
    208209                $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' );
    … …  
    559560                $local_destination = $destination;
    560561
    561                 $source_files       = array_keys( $wp_filesystem->dirlist( $remote_source ) );
     562                $dirlist = $wp_filesystem->dirlist( $remote_source );
     563
     564                if ( false === $dirlist ) {
     565                        return new WP_Error( 'source_read_failed', $this->strings['fs_error'], $this->strings['dir_not_readable'] );
     566                }
     567
     568                $source_files       = array_keys( $dirlist );
    562569                $remote_destination = $wp_filesystem->find_folder( $local_destination );
    563570
    … …  
    606613                // Has the source location changed? If so, we need a new source_files list.
    607614                if ( $source !== $remote_source ) {
    608                         $source_files = array_keys( $wp_filesystem->dirlist( $source ) );
     615                        $dirlist = $wp_filesystem->dirlist( $source );
     616
     617                        if ( false === $dirlist ) {
     618                                return new WP_Error( 'new_source_read_failed', $this->strings['fs_error'], $this->strings['dir_not_readable'] );
     619                        }
     620
     621                        $source_files = array_keys( $dirlist );
    609622                }
    610623
Note: See TracChangeset for help on using the changeset viewer.