WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 22 months ago

#17846 closed defect (bug) (fixed)

WP_Filesystem_FTPext::dirlist() doesn't handle symbolic links properly

Reported by: Oded Owned by: dd32
Milestone: 3.5 Priority: normal
Severity: normal Version: 2.5
Component: Filesystem API Keywords: has-patch
Focuses: Cc:

Description

When listing files using WP_Filesystem_FTPext::dirlist() and encountering symbolic linux on a Unix FTP server, dirlist() returns the "file name" as a symbolic link textual description such as shown by "ls -l", e.g. "linkname -> /absolute/path/to/file".

It stands to reason as this is the expected format of the FTP LIST command, but users of dirlist() are getting a structure with full details and expect the value associated with the "name" key to contain only the name of the file (or the name of the link in this case).

WP_Filesystem_FTPext should parse links properly in parselisting() and hide the extraneous data so as not to confuse users of dirlist() that expect specific file names, when the expected file name is a symbolic link.

Attachments (2)

wp-filesystem-ftpext.patch (772 bytes) - added by Oded 3 years ago.
Patch to add parsing of link details and normalization of the link name
17846.patch (643 bytes) - added by kurtpayne 2 years ago.
Refreshed patch

Download all attachments as: .zip

Change History (10)

Oded3 years ago

Patch to add parsing of link details and normalization of the link name

comment:1 SergeyBiryukov3 years ago

  • Keywords has-patch added

kurtpayne2 years ago

Refreshed patch

comment:2 kurtpayne2 years ago

  • Cc kpayne@… added

Refreshed, condensed, and tested patch. Looks good.

comment:3 Guss772 years ago

Thanks. Your patch looks fine. I wanted to do the test, under the assumption that there are operating systems where a link as output from the PHP ftp dir list may not look like that - but if you are sure, then I'm 100% behind that.

comment:4 kurtpayne2 years ago

I have tested this on Windows + FileZilla Server (wasn't able to create symlinks here) and CentOS + vsftpd (with symlinks of varied and complex names).

The WP_Filesystem_FTPext::dirlist() method uses ftp_rawlist() to get a file listing. There is no standard format for this listing, so WP can't be assured that symlinks will be represented in a -> b format. But the regex is targeted for that format and should skip over any new formats. It should be a safe fix.

comment:5 kurtpayne2 years ago

  • Version set to 2.5

comment:6 dd3222 months ago

  • Milestone changed from Awaiting Review to 3.5

comment:7 dd3222 months ago

The Direct method doesn't appear to be affected, Both the PHP Extension and the FTP Sockets classes were affected.

I can't test the SSH2 extension - but it generally works somewhere in between both, but it's life is limited (Although i've been saying that for over a year: #16925 & http://wordpress.org/extend/plugins/ssh-sftp-updater-support/ ).

I've tested kurtpayne's patch, and it appears to work as expected.

comment:8 dd3222 months ago

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

In [21223]:

WP_Filesystem: Return symlinked directory names correctly, previously the FTP extensions would return it as 'source -> dest' instead of simply 'source'. Props kurtpayne. Fixes #17846

Note: See TracTickets for help on using tickets.