]> granicus.if.org Git - php/commitdiff
Add missing ZPP checks
authorMáté Kocsis <kocsismate@woohoolabs.com>
Thu, 31 Oct 2019 09:20:41 +0000 (10:20 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 1 Nov 2019 14:26:52 +0000 (15:26 +0100)
Closes GH-4878.

17 files changed:
Zend/tests/bug71221.phpt
Zend/zend_builtin_functions.c
Zend/zend_weakrefs.c
ext/date/php_date.c
ext/dom/node.c
ext/intl/common/common_error.c
ext/intl/uchar/uchar.c
ext/mysqli/mysqli_api.c
ext/mysqli/mysqli_nonapi.c
ext/mysqli/tests/mysqli_connect_errno.phpt
ext/mysqli/tests/mysqli_connect_error.phpt
ext/mysqli/tests/mysqli_pconn_max_links.phpt
ext/mysqli/tests/mysqli_report.phpt
ext/openssl/openssl.c
ext/pdo/pdo_stmt.c
ext/pdo_pgsql/pgsql_driver.c
ext/session/session.c

index eeba6450ab90f9c9285728d686947d6ea6eb17cc..b55a14a2bdccc2489922bfb66daa4d9c28b8aba2 100644 (file)
@@ -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
index f16bf1540f91e95c2f12984a3a89bda9283a036e..a369b1eab729ddb628f0359c770426349f13a595 100644 (file)
@@ -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;
        }
@@ -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
index 0d6b9345f68dec6f06646ebe98adc926af565dcb..d7531af285f2374d98f09c826e4d38227c4d3da5 100644 (file)
@@ -152,7 +152,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();
 
@@ -165,8 +165,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);
 }
index bc0b68886317d7ca8d259e9d0cd47c46161601b2..ed0c438d04f57b3f03c546682ce9cbf7bd444f1b 100644 (file)
@@ -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);
@@ -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));
@@ -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);
@@ -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);
@@ -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);
        }
@@ -4467,6 +4475,8 @@ PHP_FUNCTION(timezone_version_get)
 {
        const timelib_tzdb *tzdb;
 
+       ZEND_PARSE_PARAMETERS_NONE();
+
        tzdb = DATE_TIMEZONEDB;
        RETURN_STRING(tzdb->version);
 }
@@ -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;
@@ -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);
index ab2151f290f86269425bd0733eeb1189b3c31acf..c15868a9ae163a125891800e5a9d5172aba01ced 100644 (file)
@@ -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);
index 85d5595dcceaee54753e133a86e3a59eb4872c05..883c45f5fe6cd7b9083b693cd9b4d5831f254bc6 100644 (file)
  */
 PHP_FUNCTION( intl_get_error_code )
 {
+       if (zend_parse_parameters_none() == FAILURE) {
+               return;
+       }
+
        RETURN_LONG( intl_error_get_code( NULL ) );
 }
 /* }}} */
@@ -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 ));
 }
 /* }}} */
index 0d4a2a60972e4b52a6f24bf1d5997426d39c017c..3d6f7519cc19ed54d95c9bc6dd4f59d641ec3395 100644 (file)
@@ -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);
index 1e19fed52ba2c57badad7b619b8371f7d47caf1c..aac3134a5985d77c46b24734d6c3aa664e210cc8 100644 (file)
@@ -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);
@@ -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());
 }
 /* }}} */
@@ -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;
        }
@@ -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());
 }
 /* }}} */
index cf641fd7b8411a143bfe61edfc406cd14a572a0f..6c47d0a66ad2dd8e2e8425015553fe9cfa8677e3 100644 (file)
@@ -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));
 }
 /* }}} */
@@ -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 {
@@ -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));
index e596a1891abbadd9588e58c9c5f2abf3801ab9b1..995eeaeb277b26e077a7a885e168d611c3c12889 100644 (file)
@@ -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",
@@ -37,4 +40,5 @@ require_once('skipifconnectfailure.inc');
        print "done!";
 ?>
 --EXPECT--
+mysqli_connect_errno() expects exactly 0 parameters, 1 given
 done!
index d0c79d6c71f7c5e4a7c5b4f380121ea005148715..40b2c7e4b449a0d52045f5e05f509576ec49d173 100644 (file)
@@ -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",
@@ -36,4 +39,5 @@ require_once('skipifconnectfailure.inc');
        print "done!";
 ?>
 --EXPECT--
+mysqli_connect_error() expects exactly 0 parameters, 1 given
 done!
index 221be0699fe2b51fc5d9ec638c300165c9ace314..19105b3c66ef31d418e7f357690a497393e8c6c2 100644 (file)
@@ -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());
@@ -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)
index 6215e6508c7f60a99ec1087318c605e6338d62df..e86c6ed6deea94d57c980d73931943955e2a7c7c 100644 (file)
@@ -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);
index d4a1ba96bfefb8209ac69f484e26c00dcf88afda..94335fadf9b1efac15cf4a52c9e5425a1f491d20 100644 (file)
@@ -6118,6 +6118,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;
index 30fb12338c8fd570d1968e4183ba9a818e6af6ed..94caae7078cbcda1df6d02d2c1bd84a68c4a33de 100644 (file)
@@ -1627,6 +1627,8 @@ static PHP_METHOD(PDOStatement, rowCount)
 {
        PHP_STMT_GET_OBJ;
 
+       ZEND_PARSE_PARAMETERS_NONE();
+
        RETURN_LONG(stmt->row_count);
 }
 /* }}} */
@@ -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;
@@ -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 {
@@ -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;
index d22c99d39941778ac25daa980f0cab50fe1e0cba..d186cb1f5ef742055c9efb0feb786f3c3a19cd5c 100644 (file)
@@ -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();
@@ -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;
 
index ecef41e290f8d19b4b8d8d34dafe41bb1666555e..db09091ac0c4490c75bc0e058c485d429742f794 100644 (file)
@@ -2645,6 +2645,8 @@ static PHP_FUNCTION(session_register_shutdown)
 {
        php_shutdown_function_entry shutdown_function_entry;
 
+       ZEND_PARSE_PARAMETERS_NONE();
+
        /* This function is registered itself as a shutdown function by
         * session_set_save_handler($obj). The reason we now register another
         * shutdown function is in case the user registered their own shutdown