WordPress.org

Make WordPress Core

Ticket #15058: validate-option-length.diff

File validate-option-length.diff, 3.7 KB (added by chrisbliss18, 4 years ago)
  • wp-includes/default-constants.php

    diff --git a/wp-includes/default-constants.php b/wp-includes/default-constants.php
    index 47b9cd7..688aac0 100644
    a b function wp_initial_constants( ) { 
    5656        if ( !defined('WP_CACHE') ) 
    5757                define('WP_CACHE', false); 
    5858 
     59        if ( !defined('WP_OPTION_LENGTH') ) 
     60                define('WP_OPTION_LENGTH', 64); 
     61 
    5962        /** 
    6063         * Private 
    6164         */ 
  • wp-includes/functions.php

    diff --git a/wp-includes/functions.php b/wp-includes/functions.php
    index 0d458ef..052dab4 100644
    a b function wp_load_core_site_options( $site_id = null ) { 
    486486 * @return bool False if value was not updated and true if value was updated. 
    487487 */ 
    488488function update_option( $option, $newvalue ) { 
     489        if ( strlen($option) > WP_OPTION_LENGTH ) { 
     490                trigger_error( sprintf( __('update_option: Option name %1$s is longer than the maximum allowed length of %2$s.'), $option, WP_OPTION_LENGTH ), E_USER_WARNING ); 
     491                return false; 
     492        } 
     493 
    489494        global $wpdb; 
    490495 
    491496        $option = trim($option); 
    function update_option( $option, $newvalue ) { 
    566571 * @return null returns when finished. 
    567572 */ 
    568573function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { 
     574        if ( strlen($option) > WP_OPTION_LENGTH ) { 
     575                trigger_error( sprintf( __('add_option: Option name %1$s is longer than the maximum allowed length of %2$s.'), $option, WP_OPTION_LENGTH ), E_USER_WARNING ); 
     576                return false; 
     577        } 
     578 
    569579        global $wpdb; 
    570580 
    571581        if ( !empty( $deprecated ) ) 
    function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) 
    633643 * @return bool True, if option is successfully deleted. False on failure. 
    634644 */ 
    635645function delete_option( $option ) { 
     646        if ( strlen($option) > WP_OPTION_LENGTH ) { 
     647                trigger_error( sprintf( __('delete_option: Option name %1$s is longer than the maximum allowed length of %2$s.'), $option, WP_OPTION_LENGTH ), E_USER_WARNING ); 
     648                return false; 
     649        } 
     650 
    636651        global $wpdb; 
    637652 
    638653        wp_protect_special_option( $option ); 
    function delete_option( $option ) { 
    676691 * @return bool true if successful, false otherwise 
    677692 */ 
    678693function delete_transient( $transient ) { 
     694        if ( strlen('_transient_timeout_' . $transient) > WP_OPTION_LENGTH ) { 
     695                trigger_error( sprintf( __('delete_transient: Transient name %1$s is longer than the maximum allowed length of %2$s.'), $transient, (WP_OPTION_LENGTH - strlen('_transient_timeout_')) ), E_USER_WARNING ); 
     696                return false; 
     697        } 
     698 
    679699        global $_wp_using_ext_object_cache; 
    680700 
    681701        do_action( 'delete_transient_' . $transient, $transient ); 
    function delete_transient( $transient ) { 
    715735 * @return mixed Value of transient 
    716736 */ 
    717737function get_transient( $transient ) { 
     738        if ( strlen('_transient_timeout_' . $transient) > WP_OPTION_LENGTH ) { 
     739                trigger_error( sprintf( __('get_transient: Transient name %1$s is longer than the maximum allowed length of %2$s.'), $transient, (WP_OPTION_LENGTH - strlen('_transient_timeout_')) ), E_USER_WARNING ); 
     740                return false; 
     741        } 
     742 
    718743        global $_wp_using_ext_object_cache; 
    719744 
    720745        $pre = apply_filters( 'pre_transient_' . $transient, false ); 
    function get_transient( $transient ) { 
    764789 * @return bool False if value was not set and true if value was set. 
    765790 */ 
    766791function set_transient( $transient, $value, $expiration = 0 ) { 
     792        if ( strlen('_transient_timeout_' . $transient) > WP_OPTION_LENGTH ) { 
     793                trigger_error( sprintf( __('set_transient: Transient name %1$s is longer than the maximum allowed length of %2$s.'), $transient, (WP_OPTION_LENGTH - strlen('_transient_timeout_')) ), E_USER_WARNING ); 
     794                return false; 
     795        } 
     796 
    767797        global $_wp_using_ext_object_cache; 
    768798 
    769799        $value = apply_filters( 'pre_set_transient_' . $transient, $value );