Skip to content

Commit d22d9eb

Browse files
bukkaremicollet
authored andcommitted
Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
Disallow null character in bcrypt password (cherry picked from commit 0ba5229a3f7572846e91c8f5382e87785f543826) (cherry picked from commit 81794c7) (cherry picked from commit 4a7ceb9) (cherry picked from commit 7471009)
1 parent ee59100 commit d22d9eb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ext/standard/password.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ PHP_FUNCTION(password_hash)
438438
cost = zval_get_long(option_buffer);
439439
}
440440

441+
if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
442+
php_error_docref(NULL, E_WARNING, "Bcrypt password must not contain null character");
443+
RETURN_NULL();
444+
}
445+
441446
if (cost < 4 || cost > 31) {
442447
php_error_docref(NULL, E_WARNING, "Invalid bcrypt cost parameter specified: " ZEND_LONG_FMT, cost);
443448
RETURN_NULL();

ext/standard/tests/password/password_bcrypt_errors.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var_dump(password_hash("foo", PASSWORD_BCRYPT, array("salt" => 123)));
1616

1717
var_dump(password_hash("foo", PASSWORD_BCRYPT, array("cost" => "foo")));
1818

19+
var_dump(password_hash("null\0password", PASSWORD_BCRYPT));
20+
1921
?>
2022
--EXPECTF--
2123
Warning: password_hash(): Invalid bcrypt cost parameter specified: 3 in %s on line %d
@@ -41,3 +43,7 @@ NULL
4143

4244
Warning: password_hash(): Invalid bcrypt cost parameter specified: 0 in %s on line %d
4345
NULL
46+
47+
Warning: password_hash(): Bcrypt password must not contain null character in %s on line %d
48+
NULL
49+

0 commit comments

Comments
 (0)