Skip to content

Commit 7471009

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)
1 parent 8642473 commit 7471009

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
@@ -467,6 +467,11 @@ PHP_FUNCTION(password_hash)
467467
cost = zval_get_long(option_buffer);
468468
}
469469

470+
if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
471+
php_error_docref(NULL, E_WARNING, "Bcrypt password must not contain null character");
472+
RETURN_NULL();
473+
}
474+
470475
if (cost < 4 || cost > 31) {
471476
php_error_docref(NULL, E_WARNING, "Invalid bcrypt cost parameter specified: " ZEND_LONG_FMT, cost);
472477
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)