Skip to content

Commit 3e800e9

Browse files
committed
Move custom type checks to ZPP
Closes GH-6034
1 parent ddc2a2d commit 3e800e9

19 files changed

+117
-122
lines changed

Zend/zend_operators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op) /* {{{ */
816816
} else {
817817
/* Previously we used strtol here, not is_numeric_string,
818818
* and strtol gives you LONG_MAX/_MIN on overflow.
819-
* We use use saturating conversion to emulate strtol()'s
819+
* We use saturating conversion to emulate strtol()'s
820820
* behaviour.
821821
*/
822822
return zend_dval_to_lval_cap(dval);

ext/mbstring/mbstring.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,8 +3513,8 @@ PHP_FUNCTION(mb_send_mail)
35133513
size_t message_len;
35143514
char *subject;
35153515
size_t subject_len;
3516-
zval *headers = NULL;
35173516
zend_string *extra_cmd = NULL;
3517+
HashTable *headers_ht = NULL;
35183518
zend_string *str_headers = NULL, *tmp_headers;
35193519
size_t n, i;
35203520
char *to_r = NULL;
@@ -3560,30 +3560,24 @@ PHP_FUNCTION(mb_send_mail)
35603560
Z_PARAM_STRING(subject, subject_len)
35613561
Z_PARAM_STRING(message, message_len)
35623562
Z_PARAM_OPTIONAL
3563-
Z_PARAM_ZVAL(headers)
3564-
Z_PARAM_STR(extra_cmd)
3563+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(str_headers, headers_ht)
3564+
Z_PARAM_STR_OR_NULL(extra_cmd)
35653565
ZEND_PARSE_PARAMETERS_END();
35663566

35673567
/* ASCIIZ check */
35683568
MAIL_ASCIIZ_CHECK_MBSTRING(to, to_len);
35693569
MAIL_ASCIIZ_CHECK_MBSTRING(subject, subject_len);
35703570
MAIL_ASCIIZ_CHECK_MBSTRING(message, message_len);
3571-
if (headers) {
3572-
switch(Z_TYPE_P(headers)) {
3573-
case IS_STRING:
3574-
tmp_headers = zend_string_init(Z_STRVAL_P(headers), Z_STRLEN_P(headers), 0);
3575-
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(tmp_headers), ZSTR_LEN(tmp_headers));
3576-
str_headers = php_trim(tmp_headers, NULL, 0, 2);
3577-
zend_string_release_ex(tmp_headers, 0);
3578-
break;
3579-
case IS_ARRAY:
3580-
str_headers = php_mail_build_headers(Z_ARRVAL_P(headers));
3581-
break;
3582-
default:
3583-
zend_argument_value_error(4, "must be of type string|array|null, %s given", zend_zval_type_name(headers));
3584-
RETURN_THROWS();
3585-
}
3571+
3572+
if (str_headers) {
3573+
tmp_headers = zend_string_init(ZSTR_VAL(str_headers), ZSTR_LEN(str_headers), 0);
3574+
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(tmp_headers), ZSTR_LEN(tmp_headers));
3575+
str_headers = php_trim(tmp_headers, NULL, 0, 2);
3576+
zend_string_release_ex(tmp_headers, 0);
3577+
} else if (headers_ht) {
3578+
str_headers = php_mail_build_headers(headers_ht);
35863579
}
3580+
35873581
if (extra_cmd) {
35883582
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(extra_cmd), ZSTR_LEN(extra_cmd));
35893583
}

ext/mbstring/mbstring.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ function mb_encode_numericentity(string $string, array $convmap, ?string $encodi
7777

7878
function mb_decode_numericentity(string $string, array $convmap, ?string $encoding = null): string {}
7979

80-
/** @param string|array|null $additional_headers */
81-
function mb_send_mail(string $to, string $subject, string $message, $additional_headers = null, ?string $additional_parameters = null): bool {}
80+
function mb_send_mail(string $to, string $subject, string $message, array|string|null $additional_headers = null, ?string $additional_parameters = null): bool {}
8281

8382
function mb_get_info(string $type = "all"): array|string|int|false {}
8483

ext/mbstring/mbstring_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 5ad8a8cf20eeae59713d19135ecccbee243754eb */
2+
* Stub hash: 84096daa0fd395f57401f11e9e79f7c8420e8a93 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_language, 0, 0, MAY_BE_STRING|MAY_BE_BOOL)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, language, IS_STRING, 1, "null")
@@ -178,7 +178,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_send_mail, 0, 3, _IS_BOOL, 0)
178178
ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0)
179179
ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0)
180180
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
181-
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, additional_headers, "null")
181+
ZEND_ARG_TYPE_MASK(0, additional_headers, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null")
182182
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_parameters, IS_STRING, 1, "null")
183183
ZEND_END_ARG_INFO()
184184

ext/oci8/oci8.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function oci_fetch_all($statement_resource, &$output, int $skip = 0, int $maximu
266266

267267
/**
268268
* @param resource $statement_resource
269-
* @param mixed $output
269+
* @param array $output
270270
* @alias oci_fetch_all
271271
* @deprecated
272272
*/

ext/oci8/oci8_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: a5a245b354b48a56c274c8f74c974d92ec430853 */
2+
* Stub hash: 447880a4bc4add36beab835cc07c09a254dc0c2b */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_oci_define_by_name, 0, 3, _IS_BOOL, 0)
55
ZEND_ARG_INFO(0, statement_resource)

ext/odbc/odbc.stub.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ function odbc_fetch_into($result_id, &$result_array, int $rownumber = 0): int|fa
5757
/** @param resource $result_id */
5858
function odbc_fetch_row($result_id, int $row_number = UNKNOWN): bool {}
5959

60-
/**
61-
* @param resource $result_id
62-
* @param string|int $field
63-
*/
64-
function odbc_result($result_id, $field): string|bool|null {}
60+
/** @param resource $result_id */
61+
function odbc_result($result_id, string|int $field): string|bool|null {}
6562

6663
/** @param resource $result_id */
6764
function odbc_result_all($result_id, string $format = ''): int|false {}

ext/odbc/odbc_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 14702a5bd87902871d456de2289f4ae236e5bfa5 */
2+
* Stub hash: cf17952d8c3b88f218bbb8d1c21ba40079574c04 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_close_all, 0, 0, IS_VOID, 0)
55
ZEND_END_ARG_INFO()
@@ -70,7 +70,7 @@ ZEND_END_ARG_INFO()
7070

7171
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_odbc_result, 0, 2, MAY_BE_STRING|MAY_BE_BOOL|MAY_BE_NULL)
7272
ZEND_ARG_INFO(0, result_id)
73-
ZEND_ARG_INFO(0, field)
73+
ZEND_ARG_TYPE_MASK(0, field, MAY_BE_STRING|MAY_BE_LONG, NULL)
7474
ZEND_END_ARG_INFO()
7575

7676
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_odbc_result_all, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)

ext/odbc/php_odbc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,31 +1736,31 @@ PHP_FUNCTION(odbc_fetch_row)
17361736
PHP_FUNCTION(odbc_result)
17371737
{
17381738
char *field;
1739-
zend_string *field_str;
1739+
zend_string *field_str, *pv_field_str;
1740+
zend_long pv_field_long;
17401741
int field_ind;
17411742
SQLSMALLINT sql_c_type = SQL_C_CHAR;
17421743
odbc_result *result;
17431744
int i = 0;
17441745
RETCODE rc;
17451746
SQLLEN fieldsize;
1746-
zval *pv_res, *pv_field;
1747+
zval *pv_res;
17471748
#ifdef HAVE_SQL_EXTENDED_FETCH
17481749
SQLULEN crow;
17491750
SQLUSMALLINT RowStatus[1];
17501751
#endif
17511752

1752-
field_ind = -1;
1753-
field = NULL;
1754-
1755-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz", &pv_res, &pv_field) == FAILURE) {
1756-
RETURN_THROWS();
1757-
}
1753+
ZEND_PARSE_PARAMETERS_START(2, 2)
1754+
Z_PARAM_RESOURCE(pv_res)
1755+
Z_PARAM_STR_OR_LONG(pv_field_str, pv_field_long)
1756+
ZEND_PARSE_PARAMETERS_END();
17581757

1759-
if (Z_TYPE_P(pv_field) == IS_STRING) {
1760-
field = Z_STRVAL_P(pv_field);
1758+
if (pv_field_str) {
1759+
field = ZSTR_VAL(pv_field_str);
1760+
field_ind = -1;
17611761
} else {
1762-
convert_to_long_ex(pv_field);
1763-
field_ind = Z_LVAL_P(pv_field) - 1;
1762+
field = NULL;
1763+
field_ind = (int) pv_field_long - 1;
17641764
}
17651765

17661766
if ((result = (odbc_result *)zend_fetch_resource(Z_RES_P(pv_res), "ODBC result", le_result)) == NULL) {

ext/xml/tests/bug72714.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ parse(3015809298423721);
2828
parse(20);
2929
?>
3030
--EXPECTF--
31-
Notice: xml_parser_set_option(): tagstart ignored, because it is out of range in %s%ebug72714.php on line %d
31+
Warning: xml_parser_set_option(): tagstart ignored, because it is out of range in %s on line %d
3232
string(9) "NS1:TOTAL"
3333
string(0) ""

0 commit comments

Comments
 (0)