From 3c814b5468697712444d103150baa37ab6f474c7 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Sat, 1 Oct 2016 06:28:30 +0000 Subject: [PATCH] Meta: Improve ID casting when getting, updating or deleting meta data. Blindly casting IDs to absolute integers in `get_metadata_by_mid()`, `update_metadata_by_mid()` and `delete_metadata_by_mid()` can cause unexpected behaviour when a floating or negative number is passed. Fixes #37746. Built from https://develop.svn.wordpress.org/trunk@38699 git-svn-id: http://core.svn.wordpress.org/trunk@38642 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 18 +++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 8833d3e987..b7ea2af9f4 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -567,12 +567,12 @@ function metadata_exists( $meta_type, $object_id, $meta_key ) { function get_metadata_by_mid( $meta_type, $meta_id ) { global $wpdb; - if ( ! $meta_type || ! is_numeric( $meta_id ) ) { + if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { return false; } - $meta_id = absint( $meta_id ); - if ( ! $meta_id ) { + $meta_id = intval( $meta_id ); + if ( $meta_id <= 0 ) { return false; } @@ -611,12 +611,12 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = global $wpdb; // Make sure everything is valid. - if ( ! $meta_type || ! is_numeric( $meta_id ) ) { + if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { return false; } - $meta_id = absint( $meta_id ); - if ( ! $meta_id ) { + $meta_id = intval( $meta_id ); + if ( $meta_id <= 0 ) { return false; } @@ -702,12 +702,12 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) { global $wpdb; // Make sure everything is valid. - if ( ! $meta_type || ! is_numeric( $meta_id ) ) { + if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) { return false; } - $meta_id = absint( $meta_id ); - if ( ! $meta_id ) { + $meta_id = intval( $meta_id ); + if ( $meta_id <= 0 ) { return false; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 2193f2a468..5d688434f0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38698'; +$wp_version = '4.7-alpha-38699'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.