Skip to content

Commit

Permalink
Don't return null from password_get_info()
Browse files Browse the repository at this point in the history
The get_info() handler should never fail, but even if it does,
we should still return a proper info array -- it doesn't make
sense that a completely incorrect hash returns an info array,
but a hash that is recognized but for which the options can't
be extracted would return null.
  • Loading branch information
nikic committed Feb 11, 2021
1 parent d80d918 commit cec5e30
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ function unpack(string $format, string $string, int $offset = 0): array|false {}

/* password.c */

function password_get_info(string $hash): ?array {}
function password_get_info(string $hash): array {}

function password_hash(string $password, string|int|null $algo, array $options = []): string {}

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 21e54280829776de72313b96e38ad2aee60bd0ee */
* Stub hash: 39cd1ddd82efd6b62605218faff8b720d8b97170 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
Expand Down Expand Up @@ -1746,7 +1746,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_unpack, 0, 2, MAY_BE_ARRAY|MAY_B
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_password_get_info, 0, 1, IS_ARRAY, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_password_get_info, 0, 1, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, hash, IS_STRING, 0)
ZEND_END_ARG_INFO()

Expand Down
7 changes: 2 additions & 5 deletions ext/standard/password.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,8 @@ PHP_FUNCTION(password_get_info)
zend_string_release(ident);

add_assoc_string(return_value, "algoName", algo->name);
if (algo->get_info &&
(FAILURE == algo->get_info(&options, hash))) {
zval_ptr_dtor_nogc(&options);
zval_ptr_dtor_nogc(return_value);
RETURN_NULL();
if (algo->get_info) {
algo->get_info(&options, hash);
}
add_assoc_zval(return_value, "options", &options);
}
Expand Down

0 comments on commit cec5e30

Please sign in to comment.