diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-22 11:30:02 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-22 11:30:02 +0200 |
commit | e547ea43c1a490d445b3d58294d12bdb17ffdf60 (patch) | |
tree | 3cef32619346c00bd4206b5dbe1b8ffb7448da66 /ext | |
parent | 0fbebfd1ae3dfc8d9e088abbb6b062f5c86f2587 (diff) | |
download | php-git-e547ea43c1a490d445b3d58294d12bdb17ffdf60.tar.gz |
http_build_query() cannot fail
Assert that ht is not null and make php_url_encode_hash_ex() return
void to clarify that this is an infallible function.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/opcache/Optimizer/zend_func_info.c | 4 | ||||
-rwxr-xr-x | ext/standard/basic_functions.stub.php | 2 | ||||
-rw-r--r-- | ext/standard/basic_functions_arginfo.h | 4 | ||||
-rw-r--r-- | ext/standard/http.c | 18 | ||||
-rw-r--r-- | ext/standard/php_http.h | 2 |
5 files changed, 10 insertions, 20 deletions
diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 87ec2e1ffa..043a660d6c 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -188,7 +188,7 @@ static const func_info_t func_infos[] = { F1("urldecode", MAY_BE_STRING), F1("rawurlencode", MAY_BE_STRING), F1("rawurldecode", MAY_BE_STRING), - F1("http_build_query", MAY_BE_FALSE | MAY_BE_STRING), + F1("http_build_query", MAY_BE_STRING), #if defined(HAVE_SYMLINK) || defined(PHP_WIN32) F1("readlink", MAY_BE_FALSE | MAY_BE_STRING), #endif @@ -344,7 +344,7 @@ static const func_info_t func_infos[] = { F0("syslog", MAY_BE_TRUE), F0("closelog", MAY_BE_TRUE), #endif - F1("metaphone", MAY_BE_FALSE | MAY_BE_STRING), + F1("metaphone", MAY_BE_STRING), F1("ob_get_flush", MAY_BE_FALSE | MAY_BE_STRING), F1("ob_get_clean", MAY_BE_FALSE | MAY_BE_STRING), F1("ob_get_status", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY), diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 0f59a2bdcd..bd185d5382 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -978,7 +978,7 @@ function pfsockopen(string $hostname, int $port = -1, &$errno = null, &$errstr = /* http.c */ -function http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $enc_type = PHP_QUERY_RFC1738): string|false {} +function http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $enc_type = PHP_QUERY_RFC1738): string {} /* image.c */ diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 6ca9dfc34c..64f35950a4 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 02f033de2ff8c06e24b22b150baa1a503ce6b95e */ + * Stub hash: d840ea5a32c8414bdc29e21635e7a36ee7c202e1 */ 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) @@ -1501,7 +1501,7 @@ ZEND_END_ARG_INFO() #define arginfo_pfsockopen arginfo_fsockopen -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_http_build_query, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_http_build_query, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, data, MAY_BE_ARRAY|MAY_BE_OBJECT, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, numeric_prefix, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg_separator, IS_STRING, 1, "null") diff --git a/ext/standard/http.c b/ext/standard/http.c index 804940fd1a..18b7c6070b 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -21,7 +21,7 @@ #define URL_DEFAULT_ARG_SEP "&" /* {{{ php_url_encode_hash */ -PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, +PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, const char *num_prefix, size_t num_prefix_len, const char *key_prefix, size_t key_prefix_len, const char *key_suffix, size_t key_suffix_len, @@ -33,14 +33,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, size_t arg_sep_len, newprefix_len, prop_len; zend_ulong idx; zval *zdata = NULL; - - if (!ht) { - return FAILURE; - } + ZEND_ASSERT(ht); if (GC_IS_RECURSIVE(ht)) { /* Prevent recursion */ - return SUCCESS; + return; } if (!arg_sep) { @@ -219,8 +216,6 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } } } ZEND_HASH_FOREACH_END(); - - return SUCCESS; } /* }}} */ @@ -241,12 +236,7 @@ PHP_FUNCTION(http_build_query) Z_PARAM_LONG(enc_type) ZEND_PARSE_PARAMETERS_END(); - if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type) == FAILURE) { - if (formstr.s) { - smart_str_free(&formstr); - } - RETURN_FALSE; - } + php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type); if (!formstr.s) { RETURN_EMPTY_STRING(); diff --git a/ext/standard/php_http.h b/ext/standard/php_http.h index b77cd0bda3..1df941ee00 100644 --- a/ext/standard/php_http.h +++ b/ext/standard/php_http.h @@ -20,7 +20,7 @@ #include "php.h" #include "zend_smart_str.h" -PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, +PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, const char *num_prefix, size_t num_prefix_len, const char *key_prefix, size_t key_prefix_len, const char *key_suffix, size_t key_suffix_len, |