Skip to content

Commit f44c2d9

Browse files
bukkaadoy
authored andcommitted
Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
Disallow null character in bcrypt password
1 parent 2b8d049 commit f44c2d9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ext/standard/password.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
180180
zval *zcost;
181181
zend_long cost = PHP_PASSWORD_BCRYPT_COST;
182182

183+
if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
184+
zend_value_error("Bcrypt password must not contain null character");
185+
return NULL;
186+
}
187+
183188
if (options && (zcost = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) {
184189
cost = zval_get_long(zcost);
185190
}

ext/standard/tests/password/password_bcrypt_errors.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ try {
1414
} catch (ValueError $exception) {
1515
echo $exception->getMessage() . "\n";
1616
}
17+
18+
try {
19+
var_dump(password_hash("null\0password", PASSWORD_BCRYPT));
20+
} catch (ValueError $e) {
21+
echo $e->getMessage(), "\n";
22+
}
1723
?>
1824
--EXPECT--
1925
Invalid bcrypt cost parameter specified: 3
2026
Invalid bcrypt cost parameter specified: 32
27+
Bcrypt password must not contain null character

0 commit comments

Comments
 (0)