Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion ext/standard/password.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I also refactor this by the way.

zend_value_error("Bcrypt password must not contain null character");
return NULL;
}
Expand Down Expand Up @@ -620,6 +620,10 @@ PHP_FUNCTION(password_verify)
ZEND_PARSE_PARAMETERS_END();

algo = php_password_algo_identify(hash);
if (algo == &php_password_algo_bcrypt && zend_str_has_nul_byte(password)) {
RETURN_FALSE;
}

RETURN_BOOL(algo && (!algo->verify || algo->verify(password, hash)));
}
/* }}} */
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