Make WordPress Core


Ignore:
Timestamp:
10/01/2016 06:27:27 AM (10 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta.php

    r38125 r38699  
    568568        global $wpdb;
    569569
    570         if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
    571                 return false;
    572         }
    573 
    574         $meta_id = absint( $meta_id );
    575         if ( ! $meta_id ) {
     570        if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
     571                return false;
     572        }
     573
     574        $meta_id = intval( $meta_id );
     575        if ( $meta_id <= 0 ) {
    576576                return false;
    577577        }
    … …  
    612612
    613613        // Make sure everything is valid.
    614         if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
    615                 return false;
    616         }
    617 
    618         $meta_id = absint( $meta_id );
    619         if ( ! $meta_id ) {
     614        if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
     615                return false;
     616        }
     617
     618        $meta_id = intval( $meta_id );
     619        if ( $meta_id <= 0 ) {
    620620                return false;
    621621        }
    … …  
    703703
    704704        // Make sure everything is valid.
    705         if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
    706                 return false;
    707         }
    708 
    709         $meta_id = absint( $meta_id );
    710         if ( ! $meta_id ) {
     705        if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
     706                return false;
     707        }
     708
     709        $meta_id = intval( $meta_id );
     710        if ( $meta_id <= 0 ) {
    711711                return false;
    712712        }
Note: See TracChangeset for help on using the changeset viewer.