Make WordPress Core


Ignore:
Timestamp:
04/06/2010 11:20:51 AM (16 years ago)
Author:
dd32
Message:

Replace use of tmpfile() with a safe get_temp_dir(). tmpfile() may use a temporary directly which is not writable. Add static caching to get_temp_dir() & better protect against bad server configs. Fixes #12866

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r13994 r14016  
    150150 */
    151151function get_temp_dir() {
     152        static $temp;
    152153        if ( defined('WP_TEMP_DIR') )
    153154                return trailingslashit(WP_TEMP_DIR);
     155
     156        if ( $temp )
     157                return trailingslashit($temp);
    154158
    155159        $temp = WP_CONTENT_DIR . '/';
     
    157161                return $temp;
    158162
    159         if  ( function_exists('sys_get_temp_dir') )
    160                 return trailingslashit(sys_get_temp_dir());
     163        if  ( function_exists('sys_get_temp_dir') ) {
     164                $temp = sys_get_temp_dir();
     165                if ( is_writable($temp) )
     166                        return trailingslashit($temp);
     167        }
    161168
    162169        $temp = ini_get('upload_tmp_dir');
    163         if ( is_dir($temp) ) // always writable
     170        if ( is_dir($temp) && is_writable($temp) )
    164171                return trailingslashit($temp);
    165172
    166         return '/tmp/';
     173        $temp = '/tmp/';
     174        return $temp;
    167175}
    168176
     
    180188 * @return string a writable filename
    181189 */
    182 function wp_tempnam($filename = '', $dir = ''){
     190function wp_tempnam($filename = '', $dir = '') {
    183191        if ( empty($dir) )
    184192                $dir = get_temp_dir();
     
    604612
    605613                if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) )
    606                         return new WP_Error('copy_failed', __('Could not copy file.'), $to . $file['filename']);
     614                        return new WP_Error('copy_failed', __('Could not copy file.'), $to . $info['filename']);
    607615        }
    608616
Note: See TracChangeset for help on using the changeset viewer.