Skip to content

Commit 70b2127

Browse files
committed
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
1 parent 69de732 commit 70b2127

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: wp-includes/version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @global string $wp_version
66
*/
7-
$wp_version = '4.9-alpha-41457';
7+
$wp_version = '4.9-alpha-41470';
88

99
/**
1010
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

Diff for: wp-includes/wp-db.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,18 @@ public function prepare( $query, $args ) {
12361236

12371237
$args = func_get_args();
12381238
array_shift( $args );
1239+
12391240
// If args were passed as an array (as in vsprintf), move them up
1240-
if ( isset( $args[0] ) && is_array($args[0]) )
1241+
if ( is_array( $args[0] ) && count( $args ) == 1 ) {
12411242
$args = $args[0];
1243+
}
1244+
1245+
foreach ( $args as $arg ) {
1246+
if ( ! is_scalar( $arg ) ) {
1247+
_doing_it_wrong( 'wpdb::prepare', sprintf( __( 'Unsupported value type (%s).' ), gettype( $arg ) ), '4.8.2' );
1248+
}
1249+
}
1250+
12421251
$query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
12431252
$query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
12441253
$query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware

0 commit comments

Comments
 (0)