WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/09/2013 02:42:52 AM (7 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-direct.php

    r23191 r25304  
    6060     * @return bool False upon failure.
    6161     */
    62     function put_contents($file, $contents, $mode = false ) {
    63         if ( ! ($fp = @fopen($file, 'w')) )
    64             return false;
    65         @fwrite($fp, $contents);
    66         @fclose($fp);
    67         $this->chmod($file, $mode);
     62    function put_contents( $file, $contents, $mode = false ) {
     63        $fp = @fopen( $file, 'wb' );
     64        if ( ! $fp )
     65            return false;
     66
     67        $bytes_written = fwrite( $fp, $contents );
     68
     69        fclose( $fp );
     70
     71        if ( false === $bytes_written || $bytes_written != strlen( $contents ) )
     72            return false;
     73
     74        $this->chmod( $file, $mode );
     75
    6876        return true;
    6977    }
Note: See TracChangeset for help on using the changeset viewer.