Skip to content

Commit 0ba5229

Browse files
bukkaramsey
authored andcommitted
Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
Disallow null character in bcrypt password
1 parent 093c08a commit 0ba5229

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
@@ -184,6 +184,11 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
184184
zval *zcost;
185185
zend_long cost = PHP_PASSWORD_BCRYPT_COST;
186186

187+
if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
188+
zend_value_error("Bcrypt password must not contain null character");
189+
return NULL;
190+
}
191+
187192
if (options && (zcost = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) {
188193
cost = zval_get_long(zcost);
189194
}

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)