Make WordPress Core

Changeset 32318


Ignore:
Timestamp:
04/27/2015 06:34:09 PM (9 years ago)
Author:
mdawaffe
Message:

3.7:

  • 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/3.7
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7/package.json

    r32286 r32318  
    11{
    22  "name": "WordPress",
    3   "version": "3.7.7",
     3  "version": "3.7.8",
    44  "description": "WordPress is web software you can use to create a beautiful website or blog.",
    55  "repository": {
  • branches/3.7/src/readme.html

    r32286 r32318  
    99<h1 id="logo">
    1010    <a href="http://wordpress.org/"><img alt="WordPress" src="wp-admin/images/wordpress-logo.png" /></a>
    11     <br /> Version 3.7.7
     11    <br /> Version 3.7.8
    1212</h1>
    1313<p style="text-align: center">Semantic Personal Publishing Platform</p>
  • branches/3.7/src/wp-admin/about.php

    r32286 r32318  
    3737
    3838<div class="changelog point-releases">
    39     <h3><?php echo _n( 'Maintenance and Security Release', 'Maintenance and Security Releases', 7 ); ?></h3>
     39    <h3><?php echo _n( 'Maintenance and Security Release', 'Maintenance and Security Releases', 8 ); ?></h3>
     40    <p><?php printf( _n( '<strong>Version %1$s</strong> addressed a security issue.',
     41         '<strong>Version %1$s</strong> addressed some security issues.', 1 ), '3.7.8' ); ?>
     42        <?php printf( __( 'For more information, see <a href="%s">the release notes</a>.' ), 'http://codex.wordpress.org/Version_3.7.8' ); ?>
     43    </p>
    4044    <p><?php printf( _n( '<strong>Version %1$s</strong> addressed %2$s bug.',
    4145         '<strong>Version %1$s</strong> addressed %2$s bugs.', 1 ), '3.7.7', number_format_i18n( 1 ) ); ?>
  • branches/3.7/src/wp-admin/includes/upgrade.php

    r28077 r32318  
    412412        upgrade_373();
    413413
     414    if ( $wp_current_db_version < 26150 )
     415        upgrade_378();
     416
    414417    maybe_disable_link_manager();
    415418
     
    12661269            $wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $post->ID ) );
    12671270            clean_post_cache( $post->ID );
     1271        }
     1272    }
     1273}
     1274
     1275/**
     1276 * Execute changes made in WordPress 3.7.8.
     1277 *
     1278 * @since 3.7.8
     1279 */
     1280function upgrade_378() {
     1281    global $wp_current_db_version, $wpdb;
     1282
     1283    if ( $wp_current_db_version < 26150 ) {
     1284        $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
     1285        if ( ! $content_length ) {
     1286            $content_length = 65535;
     1287        }
     1288
     1289        $comments = $wpdb->get_results(
     1290            "SELECT comment_ID FROM $wpdb->comments
     1291            WHERE comment_date_gmt > '2015-04-26'
     1292            AND CHAR_LENGTH( comment_content ) >= $content_length
     1293            AND ( comment_content LIKE '%<%' OR comment_content LIKE '%>%' )"
     1294        );
     1295
     1296        foreach ( $comments as $comment ) {
     1297            wp_delete_comment( $comment->comment_ID, true );
    12681298        }
    12691299    }
  • branches/3.7/src/wp-includes/version.php

    r32305 r32318  
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 26149;
     14$wp_db_version = 26150;
    1515
    1616/**
  • branches/3.7/src/wp-includes/wp-db.php

    r32275 r32318  
    15141514    protected function process_fields( $table, $data, $format ) {
    15151515        $data = $this->process_field_formats( $data, $format );
     1516        if ( false === $data ) {
     1517            return false;
     1518        }
     1519
    15161520        $data = $this->process_field_charsets( $data, $table );
     1521        if ( false === $data ) {
     1522            return false;
     1523        }
     1524
     1525        $data = $this->process_field_lengths( $data, $table );
    15171526        if ( false === $data ) {
    15181527            return false;
     
    15911600                // This isn't ASCII. Don't have strip_invalid_text() re-check.
    15921601                $value['ascii'] = false;
     1602            }
     1603
     1604            $data[ $field ] = $value;
     1605        }
     1606
     1607        return $data;
     1608    }
     1609
     1610    /**
     1611     * For string fields, record the maximum string length that field can safely save.
     1612     *
     1613     * @since 4.2.1
     1614     * @access protected
     1615     *
     1616     * @param array  $data  As it comes from the wpdb::process_field_charsets() method.
     1617     * @param string $table Table name.
     1618     * @return array|False The same array as $data with additional 'length' keys, or false if
     1619     *                     any of the values were too long for their corresponding field.
     1620     */
     1621    protected function process_field_lengths( $data, $table ) {
     1622        foreach ( $data as $field => $value ) {
     1623            if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
     1624                // We can skip this field if we know it isn't a string.
     1625                // This checks %d/%f versus ! %s because it's sprintf() could take more.
     1626                $value['length'] = false;
     1627            } else {
     1628                $value['length'] = $this->get_col_length( $table, $field );
     1629                if ( is_wp_error( $value['length'] ) ) {
     1630                    return false;
     1631                }
     1632            }
     1633
     1634            if ( false !== $value['length'] && strlen( $value['value'] ) > $value['length'] ) {
     1635                return false;
    15931636            }
    15941637
     
    19151958
    19161959    /**
     1960     * Retrieve the maximum string length allowed in a given column.
     1961     *
     1962     * @since 4.2.1
     1963     * @access public
     1964     *
     1965     * @param string $table  Table name.
     1966     * @param string $column Column name.
     1967     * @return mixed Max column length as an int. False if the column has no
     1968     *               length. WP_Error object if there was an error.
     1969     */
     1970    public function get_col_length( $table, $column ) {
     1971        $tablekey = strtolower( $table );
     1972        $columnkey = strtolower( $column );
     1973
     1974        // Skip this entirely if this isn't a MySQL database.
     1975        if ( false === $this->is_mysql ) {
     1976            return false;
     1977        }
     1978
     1979        if ( empty( $this->col_meta[ $tablekey ] ) ) {
     1980            // This primes column information for us.
     1981            $table_charset = $this->get_table_charset( $table );
     1982            if ( is_wp_error( $table_charset ) ) {
     1983                return $table_charset;
     1984            }
     1985        }
     1986
     1987        if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) {
     1988            return false;
     1989        }
     1990
     1991        $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type );
     1992
     1993        $type = strtolower( $typeinfo[0] );
     1994        if ( ! empty( $typeinfo[1] ) ) {
     1995            $length = trim( $typeinfo[1], ')' );
     1996        } else {
     1997            $length = false;
     1998        }
     1999
     2000        switch( $type ) {
     2001            case 'binary':
     2002            case 'char':
     2003            case 'varbinary':
     2004            case 'varchar':
     2005                return $length;
     2006                break;
     2007            case 'tinyblob':
     2008            case 'tinytext':
     2009                return 255; // 2^8 - 1
     2010                break;
     2011            case 'blob':
     2012            case 'text':
     2013                return 65535; // 2^16 - 1
     2014                break;
     2015            case 'mediumblob':
     2016            case 'mediumtext':
     2017                return 16777215; // 2^24 - 1
     2018                break;
     2019            case 'longblob':
     2020            case 'longtext':
     2021                return 4294967295; // 2^32 - 1
     2022                break;
     2023            default:
     2024                return false;
     2025        }
     2026
     2027        return false;
     2028    }
     2029
     2030    /**
    19172031     * Check if a string is ASCII.
    19182032     *
  • branches/3.7/tests/phpunit/tests/comment.php

    r25002 r32318  
    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/3.7/tests/phpunit/tests/db.php

    r32188 r32318  
    512512                'charset' => $expected_charset,
    513513                'ascii' => false,
     514                'length' => $wpdb->get_col_length( $wpdb->posts, 'post_content' ),
    514515            )
    515516        );
Note: See TracChangeset for help on using the changeset viewer.