Make WordPress Core

Changeset 41482 for branches/3.7/src


Ignore:
Timestamp:
09/19/2017 03:05:16 PM (9 years ago)
Author:
aaroncampbell
Message:

Database: Hardening for wpdb::prepare()

Previously if you passed an array of values for placeholders, additional values could be passed as well. Now additional values will be ignored.

Merges [41470] to 3.7 branch.

Location:
branches/3.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

  • branches/3.7/src

  • branches/3.7/src/wp-includes/wp-db.php

    r33997 r41482  
    10411041                $args = func_get_args();
    10421042                array_shift( $args );
     1043
    10431044                // If args were passed as an array (as in vsprintf), move them up
    1044                 if ( isset( $args[0] ) && is_array($args[0]) )
     1045                if ( is_array( $args[0] ) && count( $args ) == 1 ) {
    10451046                        $args = $args[0];
     1047                }
     1048
     1049                foreach ( $args as $arg ) {
     1050                        if ( ! is_scalar( $arg ) ) {
     1051                                _doing_it_wrong( 'wpdb::prepare', sprintf( 'Unsupported value type (%s).', gettype( $arg ) ), '3.7.22' );
     1052                        }
     1053                }
     1054
    10461055                $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
    10471056                $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
Note: See TracChangeset for help on using the changeset viewer.