Permalink
Browse files

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.


Built from https://develop.svn.wordpress.org/trunk@41470


git-svn-id: http://core.svn.wordpress.org/trunk@41303 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
aaroncampbell committed Sep 19, 2017
1 parent 69de732 commit 70b21279098fc973eae803693c0705a548128e48
Showing with 11 additions and 2 deletions.
  1. +1 −1 wp-includes/version.php
  2. +10 −1 wp-includes/wp-db.php
View
@@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41457';
$wp_version = '4.9-alpha-41470';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
View
@@ -1236,9 +1236,18 @@ public function prepare( $query, $args ) {
$args = func_get_args();
array_shift( $args );
// If args were passed as an array (as in vsprintf), move them up
if ( isset( $args[0] ) && is_array($args[0]) )
if ( is_array( $args[0] ) && count( $args ) == 1 ) {
$args = $args[0];
}
foreach ( $args as $arg ) {
if ( ! is_scalar( $arg ) ) {
_doing_it_wrong( 'wpdb::prepare', sprintf( __( 'Unsupported value type (%s).' ), gettype( $arg ) ), '4.8.2' );
}
}
$query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
$query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
$query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware

0 comments on commit 70b2127

Please sign in to comment.