Skip to content

Commit 63a20cb

Browse files
committed
Don't accept objects for options in password_hash()
This was likely a mixup of zpp modifiers in the original implementation. Per the RFC only arrays should be accepted here.
1 parent c43179f commit 63a20cb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

ext/standard/password.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ PHP_FUNCTION(password_needs_rehash)
614614
Z_PARAM_STR(hash)
615615
Z_PARAM_ZVAL(znew_algo)
616616
Z_PARAM_OPTIONAL
617-
Z_PARAM_ARRAY_OR_OBJECT_HT(options)
617+
Z_PARAM_ARRAY_HT(options)
618618
ZEND_PARSE_PARAMETERS_END();
619619

620620
new_algo = php_password_algo_find_zval(znew_algo);
@@ -663,7 +663,7 @@ PHP_FUNCTION(password_hash)
663663
Z_PARAM_STR(password)
664664
Z_PARAM_ZVAL(zalgo)
665665
Z_PARAM_OPTIONAL
666-
Z_PARAM_ARRAY_OR_OBJECT_HT(options)
666+
Z_PARAM_ARRAY_HT(options)
667667
ZEND_PARSE_PARAMETERS_END();
668668

669669
algo = php_password_algo_find_zval(zalgo);

ext/standard/tests/password/password_hash_error.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ try {
1212

1313
var_dump(password_hash("foo", array()));
1414

15-
var_dump(password_hash("foo", 19, new StdClass));
15+
try {
16+
var_dump(password_hash("foo", 19, new StdClass));
17+
} catch (TypeError $e) {
18+
echo $e->getMessage(), "\n";
19+
}
1620

1721
try {
1822
var_dump(password_hash("foo", PASSWORD_BCRYPT, "baz"));
@@ -34,8 +38,6 @@ Warning: Array to string conversion in %s on line %d
3438

3539
Warning: password_hash(): Unknown password hashing algorithm: Array in %s on line %d
3640
NULL
37-
38-
Warning: password_hash(): Unknown password hashing algorithm: 19 in %s on line %d
39-
NULL
41+
password_hash() expects parameter 3 to be array, object given
4042
password_hash() expects parameter 3 to be array, string given
4143
password_hash() expects parameter 1 to be string, array given

0 commit comments

Comments
 (0)