πŸ’₯ TRENDING: Ticket/ - Uncensored 2025

Opened 7 months ago

Closed 5 weeks ago

#63474 closed defect (bug) (fixed)

getchmod() can cause Fatal error

Reported by: apermo's profile apermo Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 7.0 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 (3)

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


7 months 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

#2 @SergeyBiryukov
5 weeks ago

  • Milestone changed from Awaiting Review to 7.0

#3 @SergeyBiryukov
5 weeks ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 61311:

Filesystem API: Check for the correct result in some WP_Filesystem_FTPext methods.

This avoids a PHP warning when ::dirlist() returns false under certain conditions:

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

Follow-up to [6779], [30678], [45226].

Props apermo, malt3, SergeyBiryukov.
Fixes #63474.

Note: See TracTickets for help on using tickets.