[wp-trac] [WordPress Trac] #63474: getchmod() can cause Fatal error

WordPress Trac noreply at wordpress.org
Thu May 22 09:59:41 UTC 2025


#63474: getchmod() can cause Fatal error
----------------------------+-----------------------------
 Reporter:  apermo          |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Filesystem API  |    Version:  2.5
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 `/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
 <?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
 <?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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63474>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list