From 2fabb6d0e249f14181bc8098c11854703678f715 Mon Sep 17 00:00:00 2001 From: Aaron Campbell Date: Tue, 19 Sep 2017 18:13:34 +0000 Subject: [PATCH] Database: Hardening to bring `wpdb::prepare()` inline with documentation. `wpdb::prepare()` supports %s, %d, and %F as placeholders in the query string. Any other non-escaped % will be escaped. Merges [41496] to 4.6 branch. Built from https://develop.svn.wordpress.org/branches/4.6@41499 git-svn-id: http://core.svn.wordpress.org/branches/4.6@41332 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/wp-db.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 40508bdb0e..45992aeff7 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1314,6 +1314,7 @@ class wpdb { $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting $query = preg_replace( '|(?prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length'] ); + $length = sprintf( '%.0f', $value['length']['length'] ); + $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), $length ) USING $connection_charset )", $value['value'] ); } else if ( 'binary' !== $charset ) { // If we don't have a length, there's no need to convert binary - it will always return the same result. $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] );