[php-src] PHP-8.3.5: Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true

From: Date: Tue, 09 Apr 2024 20:56:31 +0000
Subject: [php-src] PHP-8.3.5: Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-128010@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Committer: Eric Mann (ericmann) Date: 2024-04-09T11:09:33-07:00 Commit: https://github.com/php/php-src/commit/6a5c04d01d1fa9cdbfde40344c854133011107d1 Raw diff: https://github.com/php/php-src/commit/6a5c04d01d1fa9cdbfde40344c854133011107d1.diff Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true Disallow null character in bcrypt password Changed paths: M ext/standard/password.c M ext/standard/tests/password/password_bcrypt_errors.phpt Diff: diff --git a/ext/standard/password.c b/ext/standard/password.c index c3f7f73821839..6eedd8abcc152 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -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); } diff --git a/ext/standard/tests/password/password_bcrypt_errors.phpt b/ext/standard/tests/password/password_bcrypt_errors.phpt index 10c3483f5a80d..5d823cba0217d 100644 --- a/ext/standard/tests/password/password_bcrypt_errors.phpt +++ b/ext/standard/tests/password/password_bcrypt_errors.phpt @@ -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

« previous php.cvs (#128010) next »