Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#28204 closed defect (bug) (fixed)

`media_sideload_image()` tries to unlink a WP_Error object.

Reported by: georgestephanis's profile georgestephanis Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.0 Priority: low
Severity: minor Version: 2.7
Component: Media Keywords: has-patch
Focuses: Cc:

Description

Traced back to: https://core.trac.wordpress.org/changeset/8959/trunk/wp-admin/includes/media.php by @noel

Long story short, the conditional block will only be entered if $tmp is a WP_Error object, then once in, it will try to unlink $file_array['tmp_name'] -- which was just set equal to $tmp and is therefore also a WP_Error object and not a file path, so unlink will always fail!

Also, instead of setting $file_array['tmp_name'] to an empty string and causing it to fail and pass back a WP_Error later, let's just pass back the WP_Error directly.

Attachments (1)

28204.diff (1.0 KB) - added by georgestephanis 11 years ago.

Download all attachments as: .zip

Change History (4)

#2 @wonderboymusic
10 years ago

  • Milestone changed from Awaiting Review to 4.0

#3 @wonderboymusic
10 years ago

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

In 28567:

In media_sideload_image(), check the returned value of download_url() earlier to avoid attempting to unlink() an instance of WP_Error.

Props georgestephanis.
Fixes #28204.

Note: See TracTickets for help on using tickets.