Opened 7 months ago
Closed 5 weeks ago
#63474 closed defect (bug) (fixed)
getchmod() can cause Fatal error
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| 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