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

From: Date: Tue, 09 Apr 2024 18:40:58 +0000
Subject: [php-src] php-8.2.18: Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-128002@lists.php.net to get a copy of this message
Author: Jakub Zelenka (bukka) Committer: Pierrick Charron (adoy) Date: 2024-04-09T13:38:38-04:00 Commit: https://github.com/php/php-src/commit/f44c2d9f9e087218f4bd6f9313280f0b172ba104 Raw diff: https://github.com/php/php-src/commit/f44c2d9f9e087218f4bd6f9313280f0b172ba104.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 81117f17b5bcd..7056f1f85c036 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 (#128002) next »