Make WordPress Core


Ignore:
Timestamp:
09/19/2017 03:02:25 PM (8 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.0 branch.

Location:
branches/4.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

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

    r33994 r41479  
    12081208        $args = func_get_args();
    12091209        array_shift( $args );
     1210
    12101211        // If args were passed as an array (as in vsprintf), move them up
    1211         if ( isset( $args[0] ) && is_array($args[0]) )
     1212        if ( is_array( $args[0] ) && count( $args ) == 1 ) {
    12121213            $args = $args[0];
     1214        }
     1215
     1216        foreach ( $args as $arg ) {
     1217            if ( ! is_scalar( $arg ) ) {
     1218                _doing_it_wrong( 'wpdb::prepare', sprintf( 'Unsupported value type (%s).', gettype( $arg ) ), '4.0.19' );
     1219            }
     1220        }
     1221
    12131222        $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
    12141223        $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
Note: See TracChangeset for help on using the changeset viewer.