[php-src] PHP-8.1.28: Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true
| From: | Jakub Zelenka via Ben Ramsey | Date: | Wed, 10 Apr 2024 05:02:42 +0000 |
| Subject: | [php-src] PHP-8.1.28: Fix bug GHSA-q6x7-frmf-grcw: password_verify can erroneously return true | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-128035@lists.php.net to get a copy of this message | ||
Author: Jakub Zelenka (bukka)
Committer: Ben Ramsey (ramsey)
Date: 2024-04-10T00:02:11-05:00
Commit: https://github.com/php/php-src/commit/11f2568767660ffe92fbc6799800e01203aad73a
Raw diff: https://github.com/php/php-src/commit/11f2568767660ffe92fbc6799800e01203aad73a.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 651cffc9fe656..fbe58da603053 100644
--- a/ext/standard/password.c
+++ b/ext/standard/password.c
@@ -184,6 +184,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