Skip to content

Add missing ZPP checks #4878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions Zend/tests/bug71221.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
Bug #71221 (Null pointer deref (segfault) in get_defined_vars via ob_start)
--FILE--
<?php
ob_start("get_defined_vars");
try {
ob_end_clean();
} catch (\Error $e) {
echo $e->getMessage();
}
?>

OKAY
register_shutdown_function("get_defined_vars");
--EXPECT--
Cannot call get_defined_vars() dynamically
OKAY
Fatal error: Uncaught Error: Cannot call get_defined_vars() dynamically in [no active file]:0
Stack trace:
#0 [internal function]: get_defined_vars()
#1 {main}
thrown in [no active file] on line 0
5 changes: 5 additions & 0 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,9 @@ ZEND_FUNCTION(get_defined_functions)
ZEND_FUNCTION(get_defined_vars)
{
zend_array *symbol_table;

ZEND_PARSE_PARAMETERS_NONE();

if (zend_forbid_dynamic_call("get_defined_vars()") == FAILURE) {
return;
}
Expand All @@ -1637,6 +1640,8 @@ ZEND_FUNCTION(get_defined_vars)
#if ZEND_DEBUG && defined(ZTS)
ZEND_FUNCTION(zend_thread_id)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_LONG((zend_long)tsrm_thread_id());
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions Zend/zend_weakrefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ ZEND_METHOD(WeakReference, create)
{
zval *referent;

ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 1,1)
ZEND_PARSE_PARAMETERS_START(1,1)
Z_PARAM_OBJECT(referent)
ZEND_PARSE_PARAMETERS_END();

Expand All @@ -171,8 +171,7 @@ ZEND_METHOD(WeakReference, create)

ZEND_METHOD(WeakReference, get)
{
ZEND_PARSE_PARAMETERS_START_EX(ZEND_PARSE_PARAMS_THROW, 0, 0)
ZEND_PARSE_PARAMETERS_END();
ZEND_PARSE_PARAMETERS_NONE();

zend_weakref_get(getThis(), return_value);
}
Expand Down
16 changes: 15 additions & 1 deletion ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,8 @@ PHP_METHOD(DateTime, __wakeup)
php_date_obj *dateobj;
HashTable *myht;

ZEND_PARSE_PARAMETERS_NONE();

dateobj = Z_PHPDATE_P(object);

myht = Z_OBJPROP_P(object);
Expand Down Expand Up @@ -2703,6 +2705,8 @@ static void zval_from_error_container(zval *z, timelib_error_container *error) /
*/
PHP_FUNCTION(date_get_last_errors)
{
ZEND_PARSE_PARAMETERS_NONE();

if (DATEG(last_errors)) {
array_init(return_value);
zval_from_error_container(return_value, DATEG(last_errors));
Expand Down Expand Up @@ -3581,6 +3585,8 @@ PHP_METHOD(DateTimeZone, __wakeup)
php_timezone_obj *tzobj;
HashTable *myht;

ZEND_PARSE_PARAMETERS_NONE();

tzobj = Z_PHPTIMEZONE_P(object);

myht = Z_OBJPROP_P(object);
Expand Down Expand Up @@ -4064,6 +4070,8 @@ PHP_METHOD(DateInterval, __wakeup)
php_interval_obj *intobj;
HashTable *myht;

ZEND_PARSE_PARAMETERS_NONE();

intobj = Z_PHPINTERVAL_P(object);

myht = Z_OBJPROP_P(object);
Expand Down Expand Up @@ -4294,7 +4302,7 @@ PHP_METHOD(DatePeriod, __construct)
dpobj->end = clone;
}
}

if (dpobj->end == NULL && recurrences < 1) {
php_error_docref(NULL, E_WARNING, "The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences);
}
Expand Down Expand Up @@ -4467,6 +4475,8 @@ PHP_FUNCTION(timezone_version_get)
{
const timelib_tzdb *tzdb;

ZEND_PARSE_PARAMETERS_NONE();

tzdb = DATE_TIMEZONEDB;
RETURN_STRING(tzdb->version);
}
Expand All @@ -4480,6 +4490,8 @@ PHP_FUNCTION(timezone_abbreviations_list)
const timelib_tz_lookup_table *table, *entry;
zval element, *abbr_array_p, abbr_array;

ZEND_PARSE_PARAMETERS_NONE();

table = timelib_timezone_abbreviations_list();
array_init(return_value);
entry = table;
Expand Down Expand Up @@ -4940,6 +4952,8 @@ PHP_METHOD(DatePeriod, __wakeup)
php_period_obj *period_obj;
HashTable *myht;

ZEND_PARSE_PARAMETERS_NONE();

period_obj = Z_PHPPERIOD_P(object);

myht = Z_OBJPROP_P(object);
Expand Down
4 changes: 4 additions & 0 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,10 @@ PHP_METHOD(domnode, getNodePath)
dom_object *intern;
char *value;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

DOM_GET_THIS_OBJ(nodep, id, xmlNodePtr, intern);

value = (char *) xmlGetNodePath(nodep);
Expand Down
8 changes: 8 additions & 0 deletions ext/intl/common/common_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
*/
PHP_FUNCTION( intl_get_error_code )
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

RETURN_LONG( intl_error_get_code( NULL ) );
}
/* }}} */
Expand All @@ -35,6 +39,10 @@ PHP_FUNCTION( intl_get_error_code )
*/
PHP_FUNCTION( intl_get_error_message )
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

RETURN_STR(intl_error_get_message( NULL ));
}
/* }}} */
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/uchar/uchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ IC_METHOD(getUnicodeVersion) {
UVersionInfo version;
int i;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

u_getUnicodeVersion(version);
array_init(return_value);
Expand Down
16 changes: 16 additions & 0 deletions ext/mysqli/mysqli_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,10 @@ PHP_FUNCTION(mysqli_free_result)
Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_info)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

const char * info = mysql_get_client_info();
if (info) {
RETURN_STRING(info);
Expand All @@ -1385,6 +1389,10 @@ PHP_FUNCTION(mysqli_get_client_info)
Get MySQL client info */
PHP_FUNCTION(mysqli_get_client_version)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

RETURN_LONG((zend_long)mysql_get_client_version());
}
/* }}} */
Expand Down Expand Up @@ -1485,6 +1493,10 @@ void php_mysqli_init(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_method)
MYSQLI_RESOURCE *mysqli_resource;
MY_MYSQL *mysql;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

if (is_method && (Z_MYSQLI_P(getThis()))->ptr) {
return;
}
Expand Down Expand Up @@ -2619,6 +2631,10 @@ PHP_FUNCTION(mysqli_thread_id)
Return whether thread safety is given or not */
PHP_FUNCTION(mysqli_thread_safe)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

RETURN_BOOL(mysql_thread_safe());
}
/* }}} */
Expand Down
12 changes: 10 additions & 2 deletions ext/mysqli/mysqli_nonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ PHP_FUNCTION(mysqli_link_construct)
Returns the numerical value of the error message from last connect command */
PHP_FUNCTION(mysqli_connect_errno)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

RETURN_LONG(MyG(error_no));
}
/* }}} */
Expand All @@ -398,6 +402,10 @@ PHP_FUNCTION(mysqli_connect_errno)
Returns the text of the error message from previous MySQL operation */
PHP_FUNCTION(mysqli_connect_error)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}

if (MyG(error_msg)) {
RETURN_STRING(MyG(error_msg));
} else {
Expand Down Expand Up @@ -1268,10 +1276,10 @@ PHP_FUNCTION(mysqli_release_savepoint)
Returns information about open and cached links */
PHP_FUNCTION(mysqli_get_links_stats)
{
if (ZEND_NUM_ARGS()) {
php_error_docref(NULL, E_WARNING, "no parameters expected");
if (zend_parse_parameters_none() == FAILURE) {
return;
}

array_init(return_value);
add_assoc_long_ex(return_value, "total", sizeof("total") - 1, MyG(num_links));
add_assoc_long_ex(return_value, "active_plinks", sizeof("active_plinks") - 1, MyG(num_active_persistent));
Expand Down
8 changes: 6 additions & 2 deletions ext/mysqli/tests/mysqli_connect_errno.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ require_once('skipifconnectfailure.inc');
$link = NULL;

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

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
Expand All @@ -37,4 +40,5 @@ require_once('skipifconnectfailure.inc');
print "done!";
?>
--EXPECT--
mysqli_connect_errno() expects exactly 0 parameters, 1 given
done!
8 changes: 6 additions & 2 deletions ext/mysqli/tests/mysqli_connect_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ require_once('skipifconnectfailure.inc');
$link = NULL;

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

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
Expand All @@ -36,4 +39,5 @@ require_once('skipifconnectfailure.inc');
print "done!";
?>
--EXPECT--
mysqli_connect_error() expects exactly 0 parameters, 1 given
done!
11 changes: 7 additions & 4 deletions ext/mysqli/tests/mysqli_pconn_max_links.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ mysqli.rollback_on_cached_plink=1
mysqli_errno($plink), mysqli_error($plink));
}

var_dump(mysqli_get_links_stats(1));
try {
mysqli_get_links_stats(1);
} catch (ArgumentCountError $exception) {
echo $exception->getMessage() . "\n";
}

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

mysqli_close($link);
?>
--EXPECTF--
Warning: mysqli_get_links_stats(): no parameters expected in %s on line %d
NULL
--EXPECT--
mysqli_get_links_stats() expects exactly 0 parameters, 1 given
Before pconnect:array(3) {
["total"]=>
int(1)
Expand Down
1 change: 0 additions & 1 deletion ext/mysqli/tests/mysqli_report.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ require_once('skipifconnectfailure.inc');
!mysqli_query($link, 'DELETE FROM test WHERE id > 50', MYSQLI_USE_RESULT))
printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

$tmp = mysqli_thread_safe($link);
$tmp = mysqli_thread_id($link);

mysqli_close($link);
Expand Down
4 changes: 4 additions & 0 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6294,6 +6294,10 @@ PHP_FUNCTION(openssl_get_curve_names)
size_t i;
size_t len = EC_get_builtin_curves(NULL, 0);

if (zend_parse_parameters_none() == FAILURE) {
return;
}

curves = emalloc(sizeof(EC_builtin_curve) * len);
if (!EC_get_builtin_curves(curves, len)) {
RETURN_FALSE;
Expand Down
8 changes: 8 additions & 0 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ static PHP_METHOD(PDOStatement, rowCount)
{
PHP_STMT_GET_OBJ;

ZEND_PARSE_PARAMETERS_NONE();

RETURN_LONG(stmt->row_count);
}
/* }}} */
Expand Down Expand Up @@ -2036,6 +2038,8 @@ static PHP_METHOD(PDOStatement, nextRowset)
{
PHP_STMT_GET_OBJ;

ZEND_PARSE_PARAMETERS_NONE();

if (!stmt->methods->next_rowset) {
pdo_raise_impl_error(stmt->dbh, stmt, "IM001", "driver does not support multiple rowsets");
RETURN_FALSE;
Expand All @@ -2058,6 +2062,8 @@ static PHP_METHOD(PDOStatement, closeCursor)
{
PHP_STMT_GET_OBJ;

ZEND_PARSE_PARAMETERS_NONE();

if (!stmt->methods->cursor_closer) {
/* emulate it by fetching and discarding rows */
do {
Expand Down Expand Up @@ -2091,6 +2097,8 @@ static PHP_METHOD(PDOStatement, closeCursor)
A utility for internals hackers to debug parameter internals */
static PHP_METHOD(PDOStatement, debugDumpParams)
{
ZEND_PARSE_PARAMETERS_NONE();

php_stream *out = php_stream_open_wrapper("php://output", "w", 0, NULL);
struct pdo_bound_param_data *param;
PHP_STMT_GET_OBJ;
Expand Down
4 changes: 4 additions & 0 deletions ext/pdo_pgsql/pgsql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ static PHP_METHOD(PDO, pgsqlLOBCreate)
pdo_pgsql_db_handle *H;
Oid lfd;

ZEND_PARSE_PARAMETERS_NONE();

dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
PDO_DBH_CLEAR_ERR();
Expand Down Expand Up @@ -1107,6 +1109,8 @@ static PHP_METHOD(PDO, pgsqlGetPid)
pdo_dbh_t *dbh;
pdo_pgsql_db_handle *H;

ZEND_PARSE_PARAMETERS_NONE();

dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;

Expand Down
Loading