Add some logic into `wp_tempnam` to prevent it creating 'falsey' directory names that might get used elsewhere within WordPress.

Although this logic looks a little strange at this low level, it's the best location within the Upgrades code for it to happen.
Fixes #31811

Built from https://develop.svn.wordpress.org/trunk@31936


git-svn-id: http://core.svn.wordpress.org/trunk@31915 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2015-03-31 02:11:26 +00:00
parent a5478d7adb
commit 7e1e32909e
2 changed files with 25 additions and 11 deletions

View File

@ -141,17 +141,29 @@ function list_files( $folder = '', $levels = 100 ) {
* @param string $dir Optional. Directory to store the file in. Default empty.
* @return string a writable filename
*/
function wp_tempnam($filename = '', $dir = '') {
if ( empty($dir) )
function wp_tempnam( $filename = '', $dir = '' ) {
if ( empty( $dir ) ) {
$dir = get_temp_dir();
$filename = basename($filename);
if ( empty($filename) )
$filename = time();
}
$filename = preg_replace('|\..*$|', '.tmp', $filename);
$filename = $dir . wp_unique_filename($dir, $filename);
touch($filename);
return $filename;
if ( empty( $filename ) || '.' == $filename ) {
$filename = time();
}
// Use the basename of the given file without the extension as the name for the temporary directory
$temp_filename = basename( $filename );
$temp_filename = preg_replace( '|\.[^.]*$|', '', $temp_filename );
// If the folder is falsey, use it's parent directory name instead
if ( ! $temp_filename ) {
return wp_tempnam( dirname( $filename ), $dir );
}
$temp_filename .= '.tmp';
$temp_filename = $dir . wp_unique_filename( $dir, $temp_filename );
touch( $temp_filename );
return $temp_filename;
}
/**
@ -627,8 +639,10 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) {
// Create those directories if need be:
foreach ( $needed_dirs as $_dir ) {
if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the Dir exists upon creation failure. Less I/O this way.
// Only check to see if the Dir exists upon creation failure. Less I/O this way.
if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) ) {
return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), substr( $_dir, strlen( $to ) ) );
}
}
unset($needed_dirs);

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-beta3-31935';
$wp_version = '4.2-beta3-31936';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.