Make WordPress Core


Ignore:
Timestamp:
09/19/2017 02:59:26 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 4.6 branch.

Location:
branches/4.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

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

    r38581 r41473  
    12991299                $args = func_get_args();
    13001300                array_shift( $args );
     1301
    13011302                // If args were passed as an array (as in vsprintf), move them up
    1302                 if ( isset( $args[0] ) && is_array($args[0]) )
     1303                if ( is_array( $args[0] ) && count( $args ) == 1 ) {
    13031304                        $args = $args[0];
     1305                }
     1306
     1307                foreach ( $args as $arg ) {
     1308                        if ( ! is_scalar( $arg ) ) {
     1309                                _doing_it_wrong( 'wpdb::prepare', sprintf( 'Unsupported value type (%s).', gettype( $arg ) ), '4.6.7' );
     1310                        }
     1311                }
     1312
    13041313                $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
    13051314                $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
Note: See TracChangeset for help on using the changeset viewer.