WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#51057 closed defect (bug) (invalid)

[PHP 8] PemFTP - Fix is_resource() calls on Socket class objects

Reported by: ayeshrajans Owned by: SergeyBiryukov
Milestone: Priority: normal
Severity: normal Version:
Component: External Libraries Keywords: php8
Focuses: Cc:

Description

WordPress includes a library called PemFTP. The upstream appears to be abandoned, and we have previously made patches in that library (#33432).

In PHP 8, socket_* functions return/accept \Socket class objects that no longer returns true on is_resource() checks: https://php.watch/versions/8.0/sockets-sockets-addressinfo

The simplest and backwards compatible approach is simply check $fp !== false in place of is_resource($fp) calls. On all sockets_*() functions that creates a Socket resource, false is returned in case the operation fails, which makes the is_resource() call equivalent to !== false in PHP < 8.0, and buggy in PHP >= 8.0.

Attachments (1)

51057.patch (1.7 KB) - added by ayeshrajans 3 months ago.

Download all attachments as: .zip

Change History (6)

@ayeshrajans
3 months ago

#1 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#2 @SergeyBiryukov
3 months ago

Hmm, haven't tested it yet, but as far as I can see looking at the code, the $fp variable here is a file handle created with fopen(), not with any of the socket_*() functions. So it seems like is_resource() checks should still work?

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


3 months ago

#4 @ayeshrajans
3 months ago

  • Keywords close added
  • Resolution set to worksforme
  • Status changed from reviewing to closed

Thanks for your review @SergeyBiryukov - It indeed turns out that is_resource() is called on file resources only (which will be moved to objects eventually, but nothing to worry for now).

Sorry for wasting your time, and I appreciate your review either way 👍🏼.

#5 @SergeyBiryukov
3 months ago

  • Keywords close removed
  • Milestone 5.6 deleted
  • Resolution changed from worksforme to invalid

No worries! Thanks for the follow-up :)

Note: See TracTickets for help on using tickets.