Skip to content

Commit 6f14bee

Browse files
committed
initial fix
1 parent 43f1cd0 commit 6f14bee

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ext/standard/password.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ static bool php_password_bcrypt_needs_rehash(const zend_string *hash, zend_array
153153

154154
static bool php_password_bcrypt_verify(const zend_string *password, const zend_string *hash) {
155155
int status = 0;
156+
157+
/* password_hash() already rejects NUL bytes for bcrypt inputs. */
158+
if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
159+
return false;
160+
}
161+
156162
zend_string *ret = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1);
157163

158164
if (!ret) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
password_verify() rejects bcrypt passwords containing null bytes
3+
--FILE--
4+
<?php
5+
$hash = password_hash("foo", PASSWORD_BCRYPT);
6+
7+
var_dump(password_verify("foo", $hash));
8+
var_dump(password_verify("foo\0bar", $hash));
9+
var_dump(password_verify("\0foo", $hash));
10+
?>
11+
--EXPECT--
12+
bool(true)
13+
bool(false)
14+
bool(false)

0 commit comments

Comments
 (0)