Skip to content

Commit

Permalink
Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
Browse files Browse the repository at this point in the history
Disallow null character in bcrypt password
  • Loading branch information
bukka authored and ericmann committed Apr 9, 2024
1 parent f77e579 commit 6a5c04d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/standard/password.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_a
zval *zcost;
zend_long cost = PHP_PASSWORD_BCRYPT_COST;

if (memchr(ZSTR_VAL(password), '\0', ZSTR_LEN(password))) {
zend_value_error("Bcrypt password must not contain null character");
return NULL;
}

if (options && (zcost = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) {
cost = zval_get_long(zcost);
}
Expand Down
7 changes: 7 additions & 0 deletions ext/standard/tests/password/password_bcrypt_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ try {
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

try {
var_dump(password_hash("null\0password", PASSWORD_BCRYPT));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Invalid bcrypt cost parameter specified: 3
Invalid bcrypt cost parameter specified: 32
Bcrypt password must not contain null character

0 comments on commit 6a5c04d

Please sign in to comment.