Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ PHP NEWS
while COW violation flag is still set). (alexandre-daubois)
. Added form feed (\f) in the default trimmed characters of trim(), rtrim()
and ltrim(). (Weilin Du)
. Fixed bug GH-21673 Reject NUL bytes in bcrypt passwords passed to
password_verify(). (Weilin Du)
. Invalid mode values now throw in array_filter() instead of being silently
defaulted to 0. (Jorg Sowa)
. Fixed bug GH-21058 (error_log() crashes with message_type 3 and
Expand Down
7 changes: 6 additions & 1 deletion ext/standard/password.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ static bool php_password_bcrypt_needs_rehash(const zend_string *hash, zend_array

static bool php_password_bcrypt_verify(const zend_string *password, const zend_string *hash) {
int status = 0;

if (zend_str_has_nul_byte(password)) {
return false;
}

zend_string *ret = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1);

if (!ret) {
Expand Down Expand Up @@ -181,7 +186,7 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
zval *zcost;
zend_long cost = PHP_PASSWORD_BCRYPT_COST;

if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
if (zend_str_has_nul_byte(password)) {
zend_value_error("Bcrypt password must not contain null character");
return NULL;
}
Expand Down
14 changes: 14 additions & 0 deletions ext/standard/tests/password/password_bcrypt_null_verify.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
password_verify() rejects bcrypt passwords containing null bytes
--FILE--
<?php
$hash = password_hash("foo", PASSWORD_BCRYPT);

var_dump(password_verify("foo", $hash));
var_dump(password_verify("foo\0bar", $hash));
var_dump(password_verify("\0foo", $hash));
?>
--EXPECT--
bool(true)
bool(false)
bool(false)
Loading