WPDB: Check that AUTH_SALT is not empty.

In `wpdb::placeholder_escape()`, the key for `hash_hmac()` defaults to `AUTH_SALT`, but `hash_hmac()` will return an empty string if the key is empty.

This had the side effect of the string `{}` being incorrectly replaced with a `%` character in queries just about to be run on the database.

Props jsonfry.
Fixes #42431.


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


git-svn-id: http://core.svn.wordpress.org/trunk@41949 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2017-11-07 01:09:47 +00:00
parent 002d65112f
commit 8255d04abb
2 changed files with 2 additions and 2 deletions

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-RC1-42119'; $wp_version = '4.9-RC1-42120';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -1946,7 +1946,7 @@ class wpdb {
// If ext/hash is not present, compat.php's hash_hmac() does not support sha256. // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
$algo = function_exists( 'hash' ) ? 'sha256' : 'sha1'; $algo = function_exists( 'hash' ) ? 'sha256' : 'sha1';
// Old WP installs may not have AUTH_SALT defined. // Old WP installs may not have AUTH_SALT defined.
$salt = defined( 'AUTH_SALT' ) ? AUTH_SALT : (string) rand(); $salt = defined( 'AUTH_SALT' ) && AUTH_SALT ? AUTH_SALT : (string) rand();
$placeholder = '{' . hash_hmac( $algo, uniqid( $salt, true ), $salt ) . '}'; $placeholder = '{' . hash_hmac( $algo, uniqid( $salt, true ), $salt ) . '}';
} }