Skip to content

Commit 2204dbd

Browse files
kocsismatenikic
authored andcommitted
Add missing ZPP checks
Closes GH-4878.
1 parent 5dd5f1b commit 2204dbd

17 files changed

+106
-26
lines changed

Zend/tests/bug71221.phpt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22
Bug #71221 (Null pointer deref (segfault) in get_defined_vars via ob_start)
33
--FILE--
44
<?php
5-
ob_start("get_defined_vars");
6-
try {
7-
ob_end_clean();
8-
} catch (\Error $e) {
9-
echo $e->getMessage();
10-
}
11-
?>
12-
13-
OKAY
5+
register_shutdown_function("get_defined_vars");
146
--EXPECT--
15-
Cannot call get_defined_vars() dynamically
16-
OKAY
7+
Fatal error: Uncaught Error: Cannot call get_defined_vars() dynamically in [no active file]:0
8+
Stack trace:
9+
#0 [internal function]: get_defined_vars()
10+
#1 {main}
11+
thrown in [no active file] on line 0

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,9 @@ ZEND_FUNCTION(get_defined_functions)
16211621
ZEND_FUNCTION(get_defined_vars)
16221622
{
16231623
zend_array *symbol_table;
1624+
1625+
ZEND_PARSE_PARAMETERS_NONE();
1626+
16241627
if (zend_forbid_dynamic_call("get_defined_vars()") == FAILURE) {
16251628
return;
16261629
}
@@ -1637,6 +1640,8 @@ ZEND_FUNCTION(get_defined_vars)
16371640
#if ZEND_DEBUG && defined(ZTS)
16381641
ZEND_FUNCTION(zend_thread_id)
16391642
{
1643+
ZEND_PARSE_PARAMETERS_NONE();
1644+
16401645
RETURN_LONG((zend_long)tsrm_thread_id());
16411646
}
16421647
#endif

Zend/zend_weakrefs.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ ZEND_METHOD(WeakReference, create)
152152
{
153153
zval *referent;
154154

155-
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1,1)
155+
ZEND_PARSE_PARAMETERS_START(1,1)
156156
Z_PARAM_OBJECT(referent)
157157
ZEND_PARSE_PARAMETERS_END();
158158

@@ -165,8 +165,7 @@ ZEND_METHOD(WeakReference, create)
165165

166166
ZEND_METHOD(WeakReference, get)
167167
{
168-
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 0, 0)
169-
ZEND_PARSE_PARAMETERS_END();
168+
ZEND_PARSE_PARAMETERS_NONE();
170169

171170
zend_weakref_get(getThis(), return_value);
172171
}

ext/date/php_date.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,8 @@ PHP_METHOD(DateTime, __wakeup)
26672667
php_date_obj *dateobj;
26682668
HashTable *myht;
26692669

2670+
ZEND_PARSE_PARAMETERS_NONE();
2671+
26702672
dateobj = Z_PHPDATE_P(object);
26712673

26722674
myht = Z_OBJPROP_P(object);
@@ -2703,6 +2705,8 @@ static void zval_from_error_container(zval *z, timelib_error_container *error) /
27032705
*/
27042706
PHP_FUNCTION(date_get_last_errors)
27052707
{
2708+
ZEND_PARSE_PARAMETERS_NONE();
2709+
27062710
if (DATEG(last_errors)) {
27072711
array_init(return_value);
27082712
zval_from_error_container(return_value, DATEG(last_errors));
@@ -3581,6 +3585,8 @@ PHP_METHOD(DateTimeZone, __wakeup)
35813585
php_timezone_obj *tzobj;
35823586
HashTable *myht;
35833587

3588+
ZEND_PARSE_PARAMETERS_NONE();
3589+
35843590
tzobj = Z_PHPTIMEZONE_P(object);
35853591

35863592
myht = Z_OBJPROP_P(object);
@@ -4064,6 +4070,8 @@ PHP_METHOD(DateInterval, __wakeup)
40644070
php_interval_obj *intobj;
40654071
HashTable *myht;
40664072

4073+
ZEND_PARSE_PARAMETERS_NONE();
4074+
40674075
intobj = Z_PHPINTERVAL_P(object);
40684076

40694077
myht = Z_OBJPROP_P(object);
@@ -4294,7 +4302,7 @@ PHP_METHOD(DatePeriod, __construct)
42944302
dpobj->end = clone;
42954303
}
42964304
}
4297-
4305+
42984306
if (dpobj->end == NULL && recurrences < 1) {
42994307
php_error_docref(NULL, E_WARNING, "The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences);
43004308
}
@@ -4467,6 +4475,8 @@ PHP_FUNCTION(timezone_version_get)
44674475
{
44684476
const timelib_tzdb *tzdb;
44694477

4478+
ZEND_PARSE_PARAMETERS_NONE();
4479+
44704480
tzdb = DATE_TIMEZONEDB;
44714481
RETURN_STRING(tzdb->version);
44724482
}
@@ -4480,6 +4490,8 @@ PHP_FUNCTION(timezone_abbreviations_list)
44804490
const timelib_tz_lookup_table *table, *entry;
44814491
zval element, *abbr_array_p, abbr_array;
44824492

4493+
ZEND_PARSE_PARAMETERS_NONE();
4494+
44834495
table = timelib_timezone_abbreviations_list();
44844496
array_init(return_value);
44854497
entry = table;
@@ -4940,6 +4952,8 @@ PHP_METHOD(DatePeriod, __wakeup)
49404952
php_period_obj *period_obj;
49414953
HashTable *myht;
49424954

4955+
ZEND_PARSE_PARAMETERS_NONE();
4956+
49434957
period_obj = Z_PHPPERIOD_P(object);
49444958

49454959
myht = Z_OBJPROP_P(object);

ext/dom/node.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,10 @@ PHP_METHOD(domnode, getNodePath)
18291829
dom_object *intern;
18301830
char *value;
18311831

1832+
if (zend_parse_parameters_none() == FAILURE) {
1833+
return;
1834+
}
1835+
18321836
DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);
18331837

18341838
value = (char *) xmlGetNodePath(nodep);

ext/intl/common/common_error.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
*/
2727
PHP_FUNCTION( intl_get_error_code )
2828
{
29+
if (zend_parse_parameters_none() == FAILURE) {
30+
return;
31+
}
32+
2933
RETURN_LONG( intl_error_get_code( NULL ) );
3034
}
3135
/* }}} */
@@ -35,6 +39,10 @@ PHP_FUNCTION( intl_get_error_code )
3539
*/
3640
PHP_FUNCTION( intl_get_error_message )
3741
{
42+
if (zend_parse_parameters_none() == FAILURE) {
43+
return;
44+
}
45+
3846
RETURN_STR(intl_error_get_message( NULL ));
3947
}
4048
/* }}} */

ext/intl/uchar/uchar.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ IC_METHOD(getUnicodeVersion) {
559559
UVersionInfo version;
560560
int i;
561561

562+
if (zend_parse_parameters_none() == FAILURE) {
563+
return;
564+
}
562565

563566
u_getUnicodeVersion(version);
564567
array_init(return_value);

ext/mysqli/mysqli_api.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,10 @@ PHP_FUNCTION(mysqli_free_result)
13741374
Get MySQL client info */
13751375
PHP_FUNCTION(mysqli_get_client_info)
13761376
{
1377+
if (zend_parse_parameters_none() == FAILURE) {
1378+
return;
1379+
}
1380+
13771381
const char * info = mysql_get_client_info();
13781382
if (info) {
13791383
RETURN_STRING(info);
@@ -1385,6 +1389,10 @@ PHP_FUNCTION(mysqli_get_client_info)
13851389
Get MySQL client info */
13861390
PHP_FUNCTION(mysqli_get_client_version)
13871391
{
1392+
if (zend_parse_parameters_none() == FAILURE) {
1393+
return;
1394+
}
1395+
13881396
RETURN_LONG((zend_long)mysql_get_client_version());
13891397
}
13901398
/* }}} */
@@ -1485,6 +1493,10 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_method)
14851493
MYSQLI_RESOURCE *mysqli_resource;
14861494
MY_MYSQL *mysql;
14871495

1496+
if (zend_parse_parameters_none() == FAILURE) {
1497+
return;
1498+
}
1499+
14881500
if (is_method && (Z_MYSQLI_P(getThis()))->ptr) {
14891501
return;
14901502
}
@@ -2619,6 +2631,10 @@ PHP_FUNCTION(mysqli_thread_id)
26192631
Return whether thread safety is given or not */
26202632
PHP_FUNCTION(mysqli_thread_safe)
26212633
{
2634+
if (zend_parse_parameters_none() == FAILURE) {
2635+
return;
2636+
}
2637+
26222638
RETURN_BOOL(mysql_thread_safe());
26232639
}
26242640
/* }}} */

ext/mysqli/mysqli_nonapi.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ PHP_FUNCTION(mysqli_link_construct)
390390
Returns the numerical value of the error message from last connect command */
391391
PHP_FUNCTION(mysqli_connect_errno)
392392
{
393+
if (zend_parse_parameters_none() == FAILURE) {
394+
return;
395+
}
396+
393397
RETURN_LONG(MyG(error_no));
394398
}
395399
/* }}} */
@@ -398,6 +402,10 @@ PHP_FUNCTION(mysqli_connect_errno)
398402
Returns the text of the error message from previous MySQL operation */
399403
PHP_FUNCTION(mysqli_connect_error)
400404
{
405+
if (zend_parse_parameters_none() == FAILURE) {
406+
return;
407+
}
408+
401409
if (MyG(error_msg)) {
402410
RETURN_STRING(MyG(error_msg));
403411
} else {
@@ -1268,10 +1276,10 @@ PHP_FUNCTION(mysqli_release_savepoint)
12681276
Returns information about open and cached links */
12691277
PHP_FUNCTION(mysqli_get_links_stats)
12701278
{
1271-
if (ZEND_NUM_ARGS()) {
1272-
php_error_docref(NULL, E_WARNING, "no parameters expected");
1279+
if (zend_parse_parameters_none() == FAILURE) {
12731280
return;
12741281
}
1282+
12751283
array_init(return_value);
12761284
add_assoc_long_ex(return_value, "total", sizeof("total") - 1, MyG(num_links));
12771285
add_assoc_long_ex(return_value, "active_plinks", sizeof("active_plinks") - 1, MyG(num_active_persistent));

ext/mysqli/tests/mysqli_connect_errno.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ require_once('skipifconnectfailure.inc');
1414
$link = NULL;
1515

1616
// too many parameter
17-
if (0 !== ($tmp = @mysqli_connect_errno($link)))
18-
printf("[001] Expecting integer/0, got %s/%s\n", gettype($tmp), $tmp);
17+
try {
18+
mysqli_connect_errno($link);
19+
} catch (ArgumentCountError $exception) {
20+
print($exception->getMessage() . "\n");
21+
}
1922

2023
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
2124
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
@@ -37,4 +40,5 @@ require_once('skipifconnectfailure.inc');
3740
print "done!";
3841
?>
3942
--EXPECT--
43+
mysqli_connect_errno() expects exactly 0 parameters, 1 given
4044
done!

ext/mysqli/tests/mysqli_connect_error.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ require_once('skipifconnectfailure.inc');
1414
$link = NULL;
1515

1616
// too many parameter
17-
if (!is_null($tmp = @mysqli_connect_error($link)))
18-
printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
17+
try {
18+
mysqli_connect_error($link);
19+
} catch (ArgumentCountError $exception) {
20+
print($exception->getMessage() . "\n");
21+
}
1922

2023
if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
2124
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
@@ -36,4 +39,5 @@ require_once('skipifconnectfailure.inc');
3639
print "done!";
3740
?>
3841
--EXPECT--
42+
mysqli_connect_error() expects exactly 0 parameters, 1 given
3943
done!

ext/mysqli/tests/mysqli_pconn_max_links.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ mysqli.rollback_on_cached_plink=1
5959
mysqli_errno($plink), mysqli_error($plink));
6060
}
6161

62-
var_dump(mysqli_get_links_stats(1));
62+
try {
63+
mysqli_get_links_stats(1);
64+
} catch (ArgumentCountError $exception) {
65+
echo $exception->getMessage() . "\n";
66+
}
6367

6468
echo "Before pconnect:";
6569
var_dump(mysqli_get_links_stats());
@@ -201,9 +205,8 @@ mysqli_query($link, 'DROP USER pcontest');
201205

202206
mysqli_close($link);
203207
?>
204-
--EXPECTF--
205-
Warning: mysqli_get_links_stats(): no parameters expected in %s on line %d
206-
NULL
208+
--EXPECT--
209+
mysqli_get_links_stats() expects exactly 0 parameters, 1 given
207210
Before pconnect:array(3) {
208211
["total"]=>
209212
int(1)

ext/mysqli/tests/mysqli_report.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ require_once('skipifconnectfailure.inc');
267267
!mysqli_query($link, 'DELETE FROM test WHERE id > 50', MYSQLI_USE_RESULT))
268268
printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
269269

270-
$tmp = mysqli_thread_safe($link);
271270
$tmp = mysqli_thread_id($link);
272271

273272
mysqli_close($link);

ext/openssl/openssl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6118,6 +6118,10 @@ PHP_FUNCTION(openssl_get_curve_names)
61186118
size_t i;
61196119
size_t len = EC_get_builtin_curves(NULL, 0);
61206120

6121+
if (zend_parse_parameters_none() == FAILURE) {
6122+
return;
6123+
}
6124+
61216125
curves = emalloc(sizeof(EC_builtin_curve) * len);
61226126
if (!EC_get_builtin_curves(curves, len)) {
61236127
RETURN_FALSE;

ext/pdo/pdo_stmt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,8 @@ static PHP_METHOD(PDOStatement, rowCount)
16271627
{
16281628
PHP_STMT_GET_OBJ;
16291629

1630+
ZEND_PARSE_PARAMETERS_NONE();
1631+
16301632
RETURN_LONG(stmt->row_count);
16311633
}
16321634
/* }}} */
@@ -2036,6 +2038,8 @@ static PHP_METHOD(PDOStatement, nextRowset)
20362038
{
20372039
PHP_STMT_GET_OBJ;
20382040

2041+
ZEND_PARSE_PARAMETERS_NONE();
2042+
20392043
if (!stmt->methods->next_rowset) {
20402044
pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver does not support multiple rowsets");
20412045
RETURN_FALSE;
@@ -2058,6 +2062,8 @@ static PHP_METHOD(PDOStatement, closeCursor)
20582062
{
20592063
PHP_STMT_GET_OBJ;
20602064

2065+
ZEND_PARSE_PARAMETERS_NONE();
2066+
20612067
if (!stmt->methods->cursor_closer) {
20622068
/* emulate it by fetching and discarding rows */
20632069
do {
@@ -2091,6 +2097,8 @@ static PHP_METHOD(PDOStatement, closeCursor)
20912097
A utility for internals hackers to debug parameter internals */
20922098
static PHP_METHOD(PDOStatement, debugDumpParams)
20932099
{
2100+
ZEND_PARSE_PARAMETERS_NONE();
2101+
20942102
php_stream *out = php_stream_open_wrapper("php://output", "w", 0, NULL);
20952103
struct pdo_bound_param_data *param;
20962104
PHP_STMT_GET_OBJ;

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ static PHP_METHOD(PDO, pgsqlLOBCreate)
920920
pdo_pgsql_db_handle *H;
921921
Oid lfd;
922922

923+
ZEND_PARSE_PARAMETERS_NONE();
924+
923925
dbh = Z_PDO_DBH_P(ZEND_THIS);
924926
PDO_CONSTRUCT_CHECK;
925927
PDO_DBH_CLEAR_ERR();
@@ -1107,6 +1109,8 @@ static PHP_METHOD(PDO, pgsqlGetPid)
11071109
pdo_dbh_t *dbh;
11081110
pdo_pgsql_db_handle *H;
11091111

1112+
ZEND_PARSE_PARAMETERS_NONE();
1113+
11101114
dbh = Z_PDO_DBH_P(ZEND_THIS);
11111115
PDO_CONSTRUCT_CHECK;
11121116

0 commit comments

Comments
 (0)