Make WordPress Core

Changeset 32313


Ignore:
Timestamp:
04/27/2015 05:16:29 PM (11 years ago)
Author:
pento
Message:

4.0:

  • WPDB: Sanity check that any strings being stored in the DB are not too long to store correctly.
  • When upgrading, remove any suspicious comments.
Location:
branches/4.0
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0/package.json

    r32283 r32313  
    11{
    22  "name": "WordPress",
    3   "version": "4.0.3",
     3  "version": "4.0.4",
    44  "description": "WordPress is web software you can use to create a beautiful website or blog.",
    55  "repository": {
  • branches/4.0/src/readme.html

    r32283 r32313  
    1010<h1 id="logo">
    1111        <a href="https://wordpress.org/"><img alt="WordPress" src="wp-admin/images/wordpress-logo.png" /></a>
    12         <br /> Version 4.0.3
     12        <br /> Version 4.0.4
    1313</h1>
    1414<p style="text-align: center">Semantic Personal Publishing Platform</p>
  • branches/4.0/src/wp-admin/about.php

    r32283 r32313  
    4343
    4444<div class="changelog point-releases">
    45         <h3><?php echo _n( 'Maintenance and Security Release', 'Maintenance and Security Releases', 3 ); ?></h3>
     45        <h3><?php echo _n( 'Maintenance and Security Release', 'Maintenance and Security Releases', 4 ); ?></h3>
     46        <p><?php printf( _n( '<strong>Version %1$s</strong> addressed a security issue.',
     47         '<strong>Version %1$s</strong> addressed some security issues.', 1 ), '4.0.4' ); ?>
     48                <?php printf( __( 'For more information, see <a href="%s">the release notes</a>.' ), 'http://codex.wordpress.org/Version_4.0.4' ); ?>
     49        </p>
    4650        <p><?php printf( _n( '<strong>Version %1$s</strong> addressed %2$s bug.',
    4751         '<strong>Version %1$s</strong> addressed %2$s bugs.', 1 ), '4.0.3', number_format_i18n( 1 ) ); ?>
  • branches/4.0/src/wp-admin/includes/upgrade.php

    r29630 r32313  
    440440        if ( $wp_current_db_version < 29630 )
    441441                upgrade_400();
     442
     443        if ( $wp_current_db_version < 29631 )
     444                upgrade_404();
    442445
    443446        maybe_disable_link_manager();
     
    13281331
    13291332/**
     1333 * Execute changes made in WordPress 4.0.4.
     1334 *
     1335 * @since 4.0.4
     1336 */
     1337function upgrade_404() {
     1338        global $wp_current_db_version, $wpdb;
     1339
     1340        if ( $wp_current_db_version < 29631 ) {
     1341                $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
     1342                if ( ! $content_length ) {
     1343                        $content_length = 65535;
     1344                }
     1345
     1346                $comments = $wpdb->get_results(
     1347                        "SELECT comment_ID FROM $wpdb->comments
     1348                        WHERE comment_date_gmt > '2015-04-26'
     1349                        AND CHAR_LENGTH( comment_content ) >= $content_length
     1350                        AND ( comment_content LIKE '%<%' OR comment_content LIKE '%>%' )"
     1351                );
     1352
     1353                foreach ( $comments as $comment ) {
     1354                        wp_delete_comment( $comment->comment_ID, true );
     1355                }
     1356        }
     1357}
     1358
     1359/**
    13301360 * Execute network level changes
    13311361 *
  • branches/4.0/src/wp-includes/version.php

    r32302 r32313  
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 29630;
     14$wp_db_version = 29631;
    1515
    1616/**
  • branches/4.0/src/wp-includes/wp-db.php

    r32272 r32313  
    19291929        protected function process_fields( $table, $data, $format ) {
    19301930                $data = $this->process_field_formats( $data, $format );
     1931                if ( false === $data ) {
     1932                        return false;
     1933                }
     1934
    19311935                $data = $this->process_field_charsets( $data, $table );
     1936                if ( false === $data ) {
     1937                        return false;
     1938                }
     1939
     1940                $data = $this->process_field_lengths( $data, $table );
    19321941                if ( false === $data ) {
    19331942                        return false;
     
    20062015                                // This isn't ASCII. Don't have strip_invalid_text() re-check.
    20072016                                $value['ascii'] = false;
     2017                        }
     2018
     2019                        $data[ $field ] = $value;
     2020                }
     2021
     2022                return $data;
     2023        }
     2024
     2025        /**
     2026         * For string fields, record the maximum string length that field can safely save.
     2027         *
     2028         * @since 4.2.1
     2029         * @access protected
     2030         *
     2031         * @param array  $data  As it comes from the wpdb::process_field_charsets() method.
     2032         * @param string $table Table name.
     2033         * @return array|False The same array as $data with additional 'length' keys, or false if
     2034         *                     any of the values were too long for their corresponding field.
     2035         */
     2036        protected function process_field_lengths( $data, $table ) {
     2037                foreach ( $data as $field => $value ) {
     2038                        if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
     2039                                // We can skip this field if we know it isn't a string.
     2040                                // This checks %d/%f versus ! %s because it's sprintf() could take more.
     2041                                $value['length'] = false;
     2042                        } else {
     2043                                $value['length'] = $this->get_col_length( $table, $field );
     2044                                if ( is_wp_error( $value['length'] ) ) {
     2045                                        return false;
     2046                                }
     2047                        }
     2048
     2049                        if ( false !== $value['length'] && strlen( $value['value'] ) > $value['length'] ) {
     2050                                return false;
    20082051                        }
    20092052
     
    23362379
    23372380        /**
     2381         * Retrieve the maximum string length allowed in a given column.
     2382         *
     2383         * @since 4.2.1
     2384         * @access public
     2385         *
     2386         * @param string $table  Table name.
     2387         * @param string $column Column name.
     2388         * @return mixed Max column length as an int. False if the column has no
     2389         *               length. WP_Error object if there was an error.
     2390         */
     2391        public function get_col_length( $table, $column ) {
     2392                $tablekey = strtolower( $table );
     2393                $columnkey = strtolower( $column );
     2394
     2395                // Skip this entirely if this isn't a MySQL database.
     2396                if ( false === $this->is_mysql ) {
     2397                        return false;
     2398                }
     2399
     2400                if ( empty( $this->col_meta[ $tablekey ] ) ) {
     2401                        // This primes column information for us.
     2402                        $table_charset = $this->get_table_charset( $table );
     2403                        if ( is_wp_error( $table_charset ) ) {
     2404                                return $table_charset;
     2405                        }
     2406                }
     2407
     2408                if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) {
     2409                        return false;
     2410                }
     2411
     2412                $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type );
     2413
     2414                $type = strtolower( $typeinfo[0] );
     2415                if ( ! empty( $typeinfo[1] ) ) {
     2416                        $length = trim( $typeinfo[1], ')' );
     2417                } else {
     2418                        $length = false;
     2419                }
     2420
     2421                switch( $type ) {
     2422                        case 'binary':
     2423                        case 'char':
     2424                        case 'varbinary':
     2425                        case 'varchar':
     2426                                return $length;
     2427                                break;
     2428                        case 'tinyblob':
     2429                        case 'tinytext':
     2430                                return 255; // 2^8 - 1
     2431                                break;
     2432                        case 'blob':
     2433                        case 'text':
     2434                                return 65535; // 2^16 - 1
     2435                                break;
     2436                        case 'mediumblob':
     2437                        case 'mediumtext':
     2438                                return 16777215; // 2^24 - 1
     2439                                break;
     2440                        case 'longblob':
     2441                        case 'longtext':
     2442                                return 4294967295; // 2^32 - 1
     2443                                break;
     2444                        default:
     2445                                return false;
     2446                }
     2447
     2448                return false;
     2449        }
     2450
     2451        /**
    23382452         * Check if a string is ASCII.
    23392453         *
  • branches/4.0/tests/phpunit/tests/comment.php

    r25002 r32313  
    1515                $this->assertEquals( 0, $result );
    1616        }
     17
     18        public function test_comment_content_length() {
     19                // `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
     20                if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
     21                        $remote_addr = $_SERVER['REMOTE_ADDR'];
     22                } else {
     23                        $_SERVER['REMOTE_ADDR'] = '';
     24                }
     25
     26                $post_id = $this->factory->post->create();
     27
     28                $data = array(
     29                        'comment_post_ID' => $post_id,
     30                        'comment_author' => rand_str(),
     31                        'comment_author_url' => '',
     32                        'comment_author_email' => '',
     33                        'comment_type' => '',
     34                        'comment_content' => str_repeat( 'A', 65536 ),
     35                        'comment_date' => '2011-01-01 10:00:00',
     36                        'comment_date_gmt' => '2011-01-01 10:00:00',
     37                );
     38
     39                $id = wp_new_comment( $data );
     40
     41                $this->assertFalse( $id );
     42
     43                // Cleanup.
     44                if ( isset( $remote_addr ) ) {
     45                        $_SERVER['REMOTE_ADDR'] = $remote_addr;
     46                } else {
     47                        unset( $_SERVER['REMOTE_ADDR'] );
     48                }
     49        }
    1750}
  • branches/4.0/tests/phpunit/tests/db.php

    r32181 r32313  
    713713                                'charset' => $expected_charset,
    714714                                'ascii' => false,
     715                                'length' => $wpdb->get_col_length( $wpdb->posts, 'post_content' ),
    715716                        )
    716717                );
Note: See TracChangeset for help on using the changeset viewer.