Skip to content

Commit 735e36d

Browse files
committed
Move custom type checks to ZPP
1 parent e6044d4 commit 735e36d

21 files changed

+272
-247
lines changed

ext/mbstring/mbstring.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,7 +3495,6 @@ PHP_FUNCTION(mb_send_mail)
34953495
size_t message_len;
34963496
char *subject;
34973497
size_t subject_len;
3498-
zval *headers = NULL;
34993498
zend_string *extra_cmd = NULL;
35003499
zend_string *str_headers = NULL, *tmp_headers;
35013500
size_t n, i;
@@ -3516,7 +3515,7 @@ PHP_FUNCTION(mb_send_mail)
35163515
mbfl_memory_device device; /* automatic allocateable buffer for additional header */
35173516
const mbfl_language *lang;
35183517
int err = 0;
3519-
HashTable ht_headers;
3518+
HashTable *ht_headers;
35203519
zval *s;
35213520
extern void mbfl_memory_device_unput(mbfl_memory_device *device);
35223521
char *pp, *ee;
@@ -3537,30 +3536,29 @@ PHP_FUNCTION(mb_send_mail)
35373536
body_enc = mbfl_no2encoding(lang->mail_body_encoding);
35383537
}
35393538

3540-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|z!S!", &to, &to_len, &subject, &subject_len, &message, &message_len, &headers, &extra_cmd) == FAILURE) {
3541-
RETURN_THROWS();
3542-
}
3539+
ZEND_PARSE_PARAMETERS_START(3, 5)
3540+
Z_PARAM_STRING(to, to_len)
3541+
Z_PARAM_STRING(subject, subject_len)
3542+
Z_PARAM_STRING(message, message_len)
3543+
Z_PARAM_OPTIONAL
3544+
Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(str_headers, ht_headers)
3545+
Z_PARAM_STR_OR_NULL(extra_cmd)
3546+
ZEND_PARSE_PARAMETERS_END();
35433547

35443548
/* ASCIIZ check */
35453549
MAIL_ASCIIZ_CHECK_MBSTRING(to, to_len);
35463550
MAIL_ASCIIZ_CHECK_MBSTRING(subject, subject_len);
35473551
MAIL_ASCIIZ_CHECK_MBSTRING(message, message_len);
3548-
if (headers) {
3549-
switch(Z_TYPE_P(headers)) {
3550-
case IS_STRING:
3551-
tmp_headers = zend_string_init(Z_STRVAL_P(headers), Z_STRLEN_P(headers), 0);
3552-
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(tmp_headers), ZSTR_LEN(tmp_headers));
3553-
str_headers = php_trim(tmp_headers, NULL, 0, 2);
3554-
zend_string_release_ex(tmp_headers, 0);
3555-
break;
3556-
case IS_ARRAY:
3557-
str_headers = php_mail_build_headers(Z_ARRVAL_P(headers));
3558-
break;
3559-
default:
3560-
zend_argument_value_error(4, "must be of type string|array|null, %s given", zend_zval_type_name(headers));
3561-
RETURN_THROWS();
3562-
}
3552+
3553+
if (ht_headers) {
3554+
str_headers = php_mail_build_headers(ht_headers);
3555+
} else if (str_headers) {
3556+
tmp_headers = zend_string_init(ZSTR_VAL(str_headers), ZSTR_LEN(str_headers), 0);
3557+
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(tmp_headers), ZSTR_LEN(tmp_headers));
3558+
str_headers = php_trim(tmp_headers, NULL, 0, 2);
3559+
zend_string_release_ex(tmp_headers, 0);
35633560
}
3561+
35643562
if (extra_cmd) {
35653563
MAIL_ASCIIZ_CHECK_MBSTRING(ZSTR_VAL(extra_cmd), ZSTR_LEN(extra_cmd));
35663564
}

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/mysqli/mysqli.stub.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,16 @@ public function select_db(string $database) {}
237237
public function set_charset(string $charset) {}
238238

239239
/**
240-
* @param string|int $value
241240
* @return bool
242241
* @alias mysqli_options
243242
*/
244-
public function options(int $option, $value) {}
243+
public function options(int $option, string|int $value) {}
245244

246245
/**
247-
* @param string|int $value
248246
* @return bool
249247
* @alias mysqli_options
250248
*/
251-
public function set_opt(int $option, $value) {}
249+
public function set_opt(int $option, string|int $value) {}
252250

253251
/**
254252
* @return bool
@@ -630,8 +628,7 @@ function mysqli_num_fields(mysqli_result $mysql_result): int {}
630628

631629
function mysqli_num_rows(mysqli_result $mysqli_result): int|string {}
632630

633-
/** @param string|int $value */
634-
function mysqli_options(mysqli $mysqli_link, int $option, $value): bool {}
631+
function mysqli_options(mysqli $mysqli_link, int $option, string|int $value): bool {}
635632

636633
function mysqli_ping(mysqli $mysqli_link): bool {}
637634

@@ -752,8 +749,5 @@ function mysqli_refresh(mysqli $mysqli_link, int $options): bool {}
752749
/** @alias mysqli_real_escape_string */
753750
function mysqli_escape_string(mysqli $mysqli_link, string $string_to_escape): string {}
754751

755-
/**
756-
* @param string|int $value
757-
* @alias mysqli_options
758-
*/
759-
function mysqli_set_opt(mysqli $mysqli_link, int $option, $value): bool {}
752+
/** @alias mysqli_options */
753+
function mysqli_set_opt(mysqli $mysqli_link, int $option, string|int $value): bool {}

ext/mysqli/mysqli_api.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,15 +1679,19 @@ PHP_FUNCTION(mysqli_options)
16791679
{
16801680
MY_MYSQL *mysql;
16811681
zval *mysql_link = NULL;
1682-
zval *mysql_value;
1682+
zend_string *mysql_value_str;
1683+
zend_long mysql_value_long;
16831684
zend_long mysql_option;
16841685
unsigned int l_value;
16851686
zend_long ret;
16861687
int expected_type;
16871688

1688-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Olz", &mysql_link, mysqli_link_class_entry, &mysql_option, &mysql_value) == FAILURE) {
1689-
RETURN_THROWS();
1690-
}
1689+
ZEND_PARSE_PARAMETERS_START(3, 3)
1690+
Z_PARAM_OBJECT_OF_CLASS(mysql_link, mysqli_link_class_entry)
1691+
Z_PARAM_LONG(mysql_option)
1692+
Z_PARAM_STR_OR_LONG(mysql_value_str, mysql_value_long)
1693+
ZEND_PARSE_PARAMETERS_END();
1694+
16911695
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_INITIALIZED);
16921696

16931697
#ifndef MYSQLI_USE_MYSQLND
@@ -1698,31 +1702,20 @@ PHP_FUNCTION(mysqli_options)
16981702
}
16991703
#endif
17001704
expected_type = mysqli_options_get_option_zval_type(mysql_option);
1701-
if (expected_type != Z_TYPE_P(mysql_value)) {
1702-
switch (expected_type) {
1703-
case IS_STRING:
1704-
if (!try_convert_to_string(mysql_value)) {
1705-
RETURN_THROWS();
1706-
}
1707-
break;
1708-
case IS_LONG:
1709-
convert_to_long_ex(mysql_value);
1710-
break;
1711-
default:
1712-
break;
1705+
if (expected_type == IS_STRING) {
1706+
if (!mysql_value_str) {
1707+
zend_argument_type_error(3, "must be of type string for the chosen option");
1708+
RETURN_THROWS();
17131709
}
1714-
}
1715-
switch (expected_type) {
1716-
case IS_STRING:
1717-
ret = mysql_options(mysql->mysql, mysql_option, Z_STRVAL_P(mysql_value));
1718-
break;
1719-
case IS_LONG:
1720-
l_value = Z_LVAL_P(mysql_value);
1721-
ret = mysql_options(mysql->mysql, mysql_option, (char *)&l_value);
1722-
break;
1723-
default:
1724-
ret = 1;
1725-
break;
1710+
ret = mysql_options(mysql->mysql, mysql_option, ZSTR_VAL(mysql_value_str));
1711+
} else if (expected_type == IS_LONG) {
1712+
if (mysql_value_str) {
1713+
zend_argument_type_error(3, "must be of type int for the chosen option");
1714+
RETURN_THROWS();
1715+
}
1716+
ret = mysql_options(mysql->mysql, mysql_option, (char *) &mysql_value_long);
1717+
} else if (expected_type == IS_NULL) {
1718+
ret = 1;
17261719
}
17271720

17281721
RETURN_BOOL(!ret);

ext/mysqli/mysqli_arginfo.h

Lines changed: 3 additions & 3 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: a8626c7c42e4d117b08df7f42a7523f60f357b82 */
2+
* Stub hash: 5695d494cc9a1f780e65c525c47e047780bf80f1 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING)
55
ZEND_ARG_OBJ_INFO(0, mysql_link, mysqli, 0)
@@ -208,7 +208,7 @@ ZEND_END_ARG_INFO()
208208
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_options, 0, 3, _IS_BOOL, 0)
209209
ZEND_ARG_OBJ_INFO(0, mysqli_link, mysqli, 0)
210210
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
211-
ZEND_ARG_INFO(0, value)
211+
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_STRING|MAY_BE_LONG, NULL)
212212
ZEND_END_ARG_INFO()
213213

214214
#define arginfo_mysqli_ping arginfo_mysqli_more_results
@@ -545,7 +545,7 @@ ZEND_END_ARG_INFO()
545545

546546
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_options, 0, 0, 2)
547547
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
548-
ZEND_ARG_INFO(0, value)
548+
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_STRING|MAY_BE_LONG, NULL)
549549
ZEND_END_ARG_INFO()
550550

551551
#define arginfo_class_mysqli_set_opt arginfo_class_mysqli_options

ext/oci8/oci8.stub.php

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

278278
/**
279279
* @param resource $statement_resource
280-
* @param mixed $output
280+
* @param array $output
281281
* @alias oci_fetch_all
282282
* @deprecated
283283
*/

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: 1c1a73f6a4de5fa2ca9595125822d65bc4f5fc55 */
2+
* Stub hash: 2ed91ce6711e5f6c0f0ba5ab4ca3d93af05fe497 */
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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,24 +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;
1753+
ZEND_PARSE_PARAMETERS_START(2, 2)
1754+
Z_PARAM_RESOURCE(pv_res)
1755+
Z_PARAM_STR_OR_LONG(pv_field_str, pv_field_ind)
1756+
ZEND_PARSE_PARAMETERS_END();
17541757

1755-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz", &pv_res, &pv_field) == FAILURE) {
1756-
RETURN_THROWS();
1758+
if (pv_field_str) {
1759+
field = ZSTR_VAL(pv_field_str);
1760+
field_ind = -1;
1761+
} else {
1762+
field = NULL;
1763+
field_ind = pv_field_long - 1;
17571764
}
17581765

17591766
if (Z_TYPE_P(pv_field) == IS_STRING) {

ext/xml/tests/xml_parser_set_option_variation3.phpt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ $values = array(
7878

7979
foreach($values as $value) {
8080
echo @"\nArg value $value \n";
81-
var_dump( xml_parser_set_option($parser, $option, $value) );
82-
};
81+
try {
82+
var_dump(xml_parser_set_option($parser, $option, $value));
83+
} catch (TypeError $exception) {
84+
echo $exception->getMessage() . "\n";
85+
}
86+
}
8387

8488
fclose($fp);
8589
xml_parser_free($parser);
@@ -116,19 +120,19 @@ Arg value 0.5
116120
bool(true)
117121

118122
Arg value Array
119-
bool(true)
123+
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
120124

121125
Arg value Array
122-
bool(true)
126+
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
123127

124128
Arg value Array
125-
bool(true)
129+
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
126130

127131
Arg value Array
128-
bool(true)
132+
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
129133

130134
Arg value Array
131-
bool(true)
135+
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, array given
132136

133137
Arg value
134138
bool(true)
@@ -149,22 +153,20 @@ Arg value
149153
bool(true)
150154

151155
Arg value
152-
bool(true)
156+
xml_parser_set_option(): Argument #3 ($value) must be of type string for the chosen option
153157

154158
Arg value
155-
bool(true)
159+
xml_parser_set_option(): Argument #3 ($value) must be of type string for the chosen option
156160

157161
Arg value string
158-
bool(true)
162+
xml_parser_set_option(): Argument #3 ($value) must be of type string for the chosen option
159163

160164
Arg value string
161-
bool(true)
165+
xml_parser_set_option(): Argument #3 ($value) must be of type string for the chosen option
162166

163167
Arg value Some Ascii Data
164-
165-
Notice: Object of class aClass could not be converted to int in %s on line %d
166-
bool(true)
168+
xml_parser_set_option(): Argument #3 ($value) must be of type string for the chosen option
167169

168170
Arg value Resource id %s
169-
bool(true)
171+
xml_parser_set_option(): Argument #3 ($value) must be of type string|int, resource given
170172
Done

0 commit comments

Comments
 (0)