Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 16 years ago

#8428 closed defect (bug) (fixed)

wp_mkdir_p function endless recursion

Reported by: st_falcon's profile st_falcon Owned by: westi's profile westi
Milestone: 2.7 Priority: high
Severity: critical Version: 2.6.1
Component: Upload Keywords: wp_mkdir_p, upload_path
Focuses: Cc:

Description

I've moved my WP 2.6.2 to another hosting but forgot to change settings for directory to store upload data in.

On file upload I saw attempts of creating such directories:

/home/falcon/data/www/blog.stfalcon.com/wp-content/uploads/2008/11
/home/falcon/data/www/blog.stfalcon.com/wp-content/uploads/2008
/home/falcon/data/www/blog.stfalcon.com/wp-content/uploads
/home/falcon/data/www/blog.stfalcon.com/wp-content
/home/falcon/data/www/blog.stfalcon.com
/home/falcon/data/www
/home/falcon/data
/home/falcon
/home
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
... 

Seems this function shouldn't try to create any directories when / is reached.

Change History (4)

#1 @jacobsantos
17 years ago

  • Milestone set to 2.8

So basically, the problem is that you didn't change the settings and now that you did it works perfectly or that you think it should stop once it reaches the point where it no longer has permissions to precede further?

#2 @st_falcon
17 years ago

this function should just stop creating directories once / is reached.

Currently it is:

function wp_mkdir_p( $target ) {
	// from php.net/mkdir user contributed notes
	$target = str_replace( '//', '/', $target );
	if ( file_exists( $target ) )
		return @is_dir( $target );

	// Attempting to create the directory may clutter up our display.
	if ( @mkdir( $target ) ) {
		$stat = @stat( dirname( $target ) );
		$dir_perms = $stat['mode'] & 0007777;  // Get the permission bits.
		@chmod( $target, $dir_perms );
		return true;
	} elseif ( is_dir( dirname( $target ) ) ) {
			return false;
	}

	// If the above failed, attempt to create the parent node, then try again.
	if ( wp_mkdir_p( dirname( $target ) ) )
		return wp_mkdir_p( $target );

	return false;
} 

It should probably be:

	if ( wp_mkdir_p( dirname( $target ) ) && $target != '/')
		return wp_mkdir_p( $target );

#3 @westi
17 years ago

  • Component changed from General to Upload
  • Milestone changed from 2.8 to 2.7
  • Owner changed from anonymous to westi
  • Status changed from new to assigned

#4 @westi
17 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [9970]) Break out if we ever make it too far from home. Fixes #8428 props st_falcon.

Note: See TracTickets for help on using tickets.