Make WordPress Core

Opened 18 years ago

Closed 17 years ago

Last modified 17 years ago

#8830 closed defect (bug) (fixed)

wp_mkdir_p doesn't work with safe mode enabled

Reported by: remi Owned by:
Priority: normal Milestone: 3.0
Component: Filesystem API Version: 2.7
Severity: normal Keywords: needs-patch bug-hunt
Cc: Focuses:

Description

The wp_mkdir_p function (which is used by many WP features like media uploading) doesn't work when PHP's safe-mode is enabled because it allows trailing slashes at the end of the directories it tries to create.

Adding this code at the beginning of the function solves the problem:

if (substr($target, -1) == "/") {
  $target = substr($target, 0, -1);
}

Attachments (1)

8830.diff​ (447 bytes ) - added by Denis-de-Bernardy 17 years ago.

Download all attachments as: .zip

Change History (16)

#1 @Denis-de-Bernardy
17 years ago

  • Keywords has-patch tested dev-feedback added

I'm not 100% this won't have side effects

#2 @ryan
17 years ago

  • Component General → Filesystem
  • Owner anonymous removed

#3 @Denis-de-Bernardy
17 years ago

  • Keywords needs-testing added; tested removed

#4 @Denis-de-Bernardy
17 years ago

  • Milestone 2.8 → Future Release

punting pending tests

#5 @Denis-de-Bernardy
17 years ago

  • Milestone Future Release → 2.9

#6 @Denis-de-Bernardy
17 years ago

  • Keywords needs-review added; needs-testing dev-feedback removed

#7 @Denis-de-Bernardy
17 years ago

  • Keywords needs-patch added; has-patch needs-review removed
  • Milestone 2.9 → Future Release
  • Type defect (bug) → enhancement

$target = / is problematic.

#9 @scribu
17 years ago

Patch should use untrailingslashit().

#10 follow-up: @dd32
17 years ago

perhaps this should be added instead:

$target = untrailingslashit($target); 
if ( empty($target) )
  $target = '/';

#11 @dd32
17 years ago

  • Type enhancement → defect (bug)

also, this is a defect, It doesnt operate correctly under safe mode.

#12 in reply to: ↑ 10 @ryan
17 years ago

Replying to dd32:

perhaps this should be added instead:

$target = untrailingslashit($target); 
if ( empty($target) )
  $target = '/';

Sounds good.

#13 @dd32
17 years ago

  • Milestone Future Release → 3.0

#14 @automattor
17 years ago

  • Resolution → fixed
  • Status new → closed

(In [12740]) Fix wp_mkdir_p() when running under safe_mode on certain PHP versions. Props Denis-de-Bernardy. Fixes #8830

#15 @Denis-de-Bernardy
17 years ago

  • Keywords bug-hunt added
Note: See TracTickets for help on using tickets.