Make WordPress Core

Opened 5 weeks ago

Last modified 5 weeks ago

#63474 new defect (bug)

getchmod() can cause Fatal error

Reported by: apermo's profile apermo Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.5
Component: Filesystem API Keywords: has-patch
Focuses: Cc:

Description

/wp-admin/includes/class-wp-filesystem-ftpsockets.php:326: Trying to access array offset on value of type bool

In both classes WP_Filesystem_FTPext and WP_Filesystem_ftpsockets

The function getchmod() looks like this:

<?php
public function getchmod( $file ) {
        $dir = $this->dirlist( $file );

        return $dir[ $file ]['permsn'];
}

and dirlist() can in both cases return false under certain conditions.

While it is rare and I could not yet figure out how to reproduce it, this will cause a fatal error.

I suggest to add a simple condition that will check if $dir is an array, and return either an empty string or null if it's not.

This will fix the error, without delivering wrong information.

<?php
public function getchmod( $file ) {
        $dir = $this->dirlist( $file );

        if ( ! empty( $dir[ $file ]['permsn'] ) ) {
                return $dir[ $file ]['permsn'];
        }

        return '';
}

Props to @malt3 for running into it.

Change History (1)

This ticket was mentioned in PR #8827 on WordPress/wordpress-develop by @apermo.


5 weeks ago
#1

  • Keywords has-patch added

Co-authored-by: @zaphir
Ref: https://core.trac.wordpress.org/ticket/63474#ticket

Fixes 63474 in the way suggested in the ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63474#ticket

Note: See TracTickets for help on using tickets.