From 6f02bf815cbf500342f97a1003229d76103b337b Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sun, 28 Mar 2010 03:10:37 +0000 Subject: [PATCH] Do not allow empty option names. Trim leading and trailing whitespace from option names. Partial patch props ericmann. Fixes #11506 git-svn-id: https://develop.svn.wordpress.org/trunk@13858 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 4525d20ffb..751095f0ff 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -318,6 +318,10 @@ function get_option( $option, $default = false ) { if ( false !== $pre ) return $pre; + $option = trim($option); + if ( empty($option) ) + return false; + // prevent non-existent options from triggering multiple queries if ( defined( 'WP_INSTALLING' ) && is_multisite() ) { $notoptions = array(); @@ -488,6 +492,10 @@ function wp_load_core_site_options( $site_id = null ) { function update_option( $option, $newvalue ) { global $wpdb; + $option = trim($option); + if ( empty($option) ) + return false; + wp_protect_special_option( $option ); $newvalue = sanitize_option( $option, $newvalue ); @@ -559,10 +567,14 @@ function update_option( $option, $newvalue ) { * @return null returns when finished. */ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { + global $wpdb; + if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.3' ); - global $wpdb; + $option = trim($option); + if ( empty($option) ) + return false; wp_protect_special_option( $option ); $value = sanitize_option( $option, $value );