Make WordPress Core


Ignore:
Timestamp:
09/09/2013 02:42:52 AM (13 years ago)
Author:
dd32
Message:

WP_Filesystem: Ensure that all files are read/written correctly by verifying the return values from fwrite() and using FTP_BINARY mode (ASCII converts line endings as per the spec). See #25237

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

    r25274 r25304  
    7676                }
    7777
    78                 $this->ftp->SetType(FTP_AUTOASCII);
    79                 $this->ftp->Passive(true);
    80                 $this->ftp->setTimeout(FS_TIMEOUT);
     78                $this->ftp->SetType( FTP_BINARY );
     79                $this->ftp->Passive( true );
     80                $this->ftp->setTimeout( FS_TIMEOUT );
    8181                return true;
    8282        }
    8383
    84         function get_contents($file, $type = '', $resumepos = 0) {
     84        function get_contents( $file ) {
    8585                if ( ! $this->exists($file) )
    8686                        return false;
    87 
    88                 if ( empty($type) )
    89                         $type = FTP_AUTOASCII;
    90                 $this->ftp->SetType($type);
    9187
    9288                $temp = wp_tempnam( $file );
     
    123119                }
    124120
    125                 fwrite($temphandle, $contents);
    126                 fseek($temphandle, 0); //Skip back to the start of the file being written to
    127 
    128                 $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
    129                 $this->ftp->SetType($type);
     121                $bytes_written = fwrite( $temphandle, $contents );
     122                if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) {
     123                        fclose( $temphandle );
     124                        unlink( $temp );
     125                        return false;
     126                }
     127
     128                fseek( $temphandle, 0 ); // Skip back to the start of the file being written to
    130129
    131130                $ret = $this->ftp->fput($file, $temphandle);
Note: See TracChangeset for help on using the changeset viewer.