Skip to content

Commit 08d7fcc

Browse files
committed
Update password.c
1 parent 512fcdb commit 08d7fcc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

ext/standard/password.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ 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-
162156
zend_string *ret = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1);
163157

164158
if (!ret) {
@@ -187,7 +181,7 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
187181
zval *zcost;
188182
zend_long cost = PHP_PASSWORD_BCRYPT_COST;
189183

190-
if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
184+
if (zend_str_has_nul_byte(password)) {
191185
zend_value_error("Bcrypt password must not contain null character");
192186
return NULL;
193187
}
@@ -626,6 +620,10 @@ PHP_FUNCTION(password_verify)
626620
ZEND_PARSE_PARAMETERS_END();
627621

628622
algo = php_password_algo_identify(hash);
623+
if (algo == &php_password_algo_bcrypt && zend_str_has_nul_byte(password)) {
624+
RETURN_FALSE;
625+
}
626+
629627
RETURN_BOOL(algo && (!algo->verify || algo->verify(password, hash)));
630628
}
631629
/* }}} */

0 commit comments

Comments
 (0)