]> granicus.if.org Git - php/commitdiff
We don't consistently check for args passed to functions that don't
authorRasmus Lerdorf <rasmus@php.net>
Mon, 13 Aug 2001 06:43:47 +0000 (06:43 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Mon, 13 Aug 2001 06:43:47 +0000 (06:43 +0000)
take any args.  In some cases we probably want to skip the check for
performance reasons, but in other cases where performance is unlikely
to be a factor, not throwing a warning on the wrong number of args passed
to a function is at best inconsistent, and at worst it could hide a bug.
So, add a few such checks.  There are still lots of cases out there.

15 files changed:
ext/curl/curl.c
ext/db/db.c
ext/domxml/php_domxml.c
ext/fdf/fdf.c
ext/gd/gd.c
ext/hyperwave/hw.c
ext/interbase/interbase.c
ext/mhash/mhash.c
ext/odbc/php_odbc.c
ext/sablot/sablot.c
ext/session/session.c
ext/snmp/snmp.c
ext/sockets/sockets.c
ext/standard/basic_functions.c
ext/standard/info.c

index 717f97096013fe8eb44abee166209aa0b5b15865..21c2641111d336bb4de6c94c80d2206001f38b72 100644 (file)
@@ -504,6 +504,9 @@ static void curl_free_slist(void **slist)
    Return the CURL version string. */
 PHP_FUNCTION(curl_version)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_STRING(curl_version(), 1);
 }
 /* }}} */
index 4ef741738f80f30c4eaa3380e2c2ec2bda74cba7..cf0712da7186d294444b7cfb3ef6e10b5aec5658 100644 (file)
@@ -252,6 +252,9 @@ PHP_MINFO_FUNCTION(db)
    Describes the dbm-compatible library being used */ 
 PHP_FUNCTION(dblist)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        char *str = php_get_info_db();
        RETURN_STRING(str, 1);
 }
index aa638404174b4392ca8d026535eb22e73c056c76..d1a3042a119e73658a978deba2cac71f4ebd6a95 100644 (file)
@@ -2432,6 +2432,9 @@ PHP_FUNCTION(xmltree)
    Initializing XPath environment */
 PHP_FUNCTION(xpath_init)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        xmlXPathInit();
        RETURN_TRUE;
 }
index a1b880a46c57b6b15879b265b7f48a9804e57b25..f09b7433da071a3a85df00a3b4bade67701e1b3c 100644 (file)
@@ -209,6 +209,9 @@ PHP_FUNCTION(fdf_create)
        FDFDoc fdf;
        FDFErc err;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        err = FDFCreate(&fdf);
 
        if(err != FDFErcOK || !fdf) {
index f7e781ef3ea7ceda220697506481f3b8966e1500..e00f3c26e78a2d79efe97feb4294b724d6cbefa1 100644 (file)
@@ -931,6 +931,9 @@ PHP_FUNCTION(imagetypes)
 #ifdef HAVE_GD_XPM
        ret |= 16;
 #endif
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_LONG(ret);
 }
 /* }}} */
index 8f3120e858eada8c28acbb432e63bcaec60c9cf8..a00e1c7fa3f0ae809a40f2636e7d3e218fbc5eac 100644 (file)
@@ -1331,6 +1331,9 @@ PHP_FUNCTION(hw_errormsg)
    Returns object id of root collection */
 PHP_FUNCTION(hw_root)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        return_value->value.lval = 0;
        return_value->type = IS_LONG;
 }
index 273520c58f1740ef42a695815beb022abdca7e12..0ed2c2412a973e42dd53284f3e2430754b45e78d 100644 (file)
@@ -236,6 +236,9 @@ typedef struct {
    Return error message */
 PHP_FUNCTION(ibase_errmsg)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        if (IBG(errmsg[0])) {
                RETURN_STRING(IBG(errmsg), 1);
        }
index e630b7c3929ff8c1f9555f60e964e9f5227e6a21..d6ad84c7cfe7c24d43dfd6d3398543dced20ac0f 100644 (file)
@@ -83,6 +83,9 @@ static PHP_MINIT_FUNCTION(mhash)
    Gets the number of available hashes */
 PHP_FUNCTION(mhash_count)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_LONG(mhash_count());
 }
 
index ab0638ed10b6b809fb4c94e908ad23a5dabbfc7e..951e35a1618b952bd363c0dfec50ac4cd199821d 100644 (file)
@@ -710,7 +710,10 @@ PHP_FUNCTION(odbc_close_all)
        int type;
        int i;
        int nument;
-       
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return; 
+
        nument = zend_hash_next_free_element(&EG(regular_list));
        
        /* Loop through list and close all statements */
index d5b7e031dfc501966f448f05d707755f8095ef5c..3d1a73609fcf336032c400a099822396ac551e76 100644 (file)
@@ -291,7 +291,10 @@ PHP_FUNCTION(xslt_output_endtransform)
     char *tRes   = NULL,
          *buffer = NULL;
     int ret = 0;
-    
+   
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
     /** 
      * Make sure that we don't have more than one output buffer going on
      * at the same time.
@@ -556,7 +559,10 @@ PHP_FUNCTION(xslt_create)
     php_sablot *handle;
     SablotHandle p;
     int ret;
-    
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
     ret = SablotCreateProcessor(&p);
     
     if (ret) {
index 1372c0b5cf08180f7502c33900075b0b75bc625c..7ed6ad84d97f96d71902b922fbb479e146cd04cc 100644 (file)
@@ -1229,6 +1229,9 @@ PHP_FUNCTION(session_encode)
        int len;
        char *enc;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        enc = php_session_encode(&len TSRMLS_CC);
        RETVAL_STRINGL(enc, len, 0);
 }
@@ -1253,6 +1256,7 @@ PHP_FUNCTION(session_decode)
    Begin session - reinitializes freezed variables, registers browsers etc */
 PHP_FUNCTION(session_start)
 {
+       /* skipping check for non-zero args for performance reasons here ?*/
        php_session_start(TSRMLS_C);
        RETURN_TRUE;
 }
@@ -1262,6 +1266,9 @@ PHP_FUNCTION(session_start)
    Destroy the current session and all data associated with it */
 PHP_FUNCTION(session_destroy)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        if (php_session_destroy(TSRMLS_C) == SUCCESS) {
                RETURN_TRUE;
        } else {
index 6b635b196a228a874f65eeab34e050a69d4d5cb1..56c87e4dc49416cc43e0804b266eda3d9949a33d 100644 (file)
@@ -402,6 +402,9 @@ PHP_FUNCTION(snmprealwalk)
    Return the current status of quick_print */
 PHP_FUNCTION(snmp_get_quick_print)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_LONG(snmp_get_quick_print() ? 1 : 0);
 }
 /* }}} */
@@ -410,12 +413,12 @@ PHP_FUNCTION(snmp_get_quick_print)
    Return all objects including their respective object id withing the specified one */
 PHP_FUNCTION(snmp_set_quick_print)
 {
-       zval **a1;
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &a1) == FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-       convert_to_long_ex(a1);
-       snmp_set_quick_print((int)(*a1)->value.lval);
+       int argc = ZEND_NUM_ARGS();
+       long a1;
+
+       if (zend_parse_parameters(argc, "l", &a1) == FAILURE)
+               return;
+       snmp_set_quick_print((int)a1);
 }
 /* }}} */
 
index 8e18d28697dd4a17bd0acf4a110ee70cad266d02..d8629f0b42e34bd19d8dee714d8013825040959a 100644 (file)
@@ -397,6 +397,9 @@ PHP_FUNCTION(socket_fd_alloc)
 {
        php_fd_set *php_fd;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        php_fd = (php_fd_set*)emalloc(sizeof(php_fd_set));
 
        FD_ZERO(&(php_fd->set));
index 5501934deec482e60be16a43ac318062b6000d78..17b093bf59dc22b31a1cce1efae9f43047821c7f 100644 (file)
@@ -1316,6 +1316,9 @@ PHP_FUNCTION(settype)
    Get the name of the owner of the current PHP script */
 PHP_FUNCTION(get_current_user)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_STRING(php_get_current_user(), 1);
 }
 /* }}} */
index 27fa7d4edb53b6c4a1cd7598ce60eaaf57078d69..a1f50d9604ab1467bd3b002bcd50117c9af5c79e 100644 (file)
@@ -455,26 +455,16 @@ void register_phpinfo_constants(INIT_FUNC_ARGS)
    Output a page of useful information about PHP and the current request */
 PHP_FUNCTION(phpinfo)
 {
-       int flag;
-       zval **flag_arg;
+       int argc = ZEND_NUM_ARGS();
+       long flag;
 
+       if (zend_parse_parameters(argc, "|l", &flag) == FAILURE)
+               return;
 
-       switch (ZEND_NUM_ARGS()) {
-               case 0:
-                       flag = 0xFFFFFFFF;
-                       break;
-               case 1:
-                       if (zend_get_parameters_ex(1, &flag_arg)==FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(flag_arg);
-                       flag = (*flag_arg)->value.lval;
-                       break;
-               default:
-                       WRONG_PARAM_COUNT;
-                       break;
+       if(!argc) {
+               flag = 0xFFFFFFFF;
        }
-       php_print_info(flag TSRMLS_CC);
+
        RETURN_TRUE;
 }
 
@@ -484,6 +474,9 @@ PHP_FUNCTION(phpinfo)
    Return the current PHP version */
 PHP_FUNCTION(phpversion)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
     RETURN_STRING(PHP_VERSION, 1);
 }
 /* }}} */
@@ -492,35 +485,28 @@ PHP_FUNCTION(phpversion)
    Prints the list of people who've contributed to the PHP project */
 PHP_FUNCTION(phpcredits)
 {
-       int flag;
-       zval **flag_arg;
+       int argc = ZEND_NUM_ARGS();
+       long flag;
 
+       if (zend_parse_parameters(argc, "|l", &flag) == FAILURE)
+               return;
+
+       if(!argc) {
+               flag = 0xFFFFFFFF;
+       } 
 
-       switch (ZEND_NUM_ARGS()) {
-               case 0:
-                       flag = 0xFFFFFFFF;
-                       break;
-               case 1:
-                       if (zend_get_parameters_ex(1, &flag_arg)==FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       convert_to_long_ex(flag_arg);
-                       flag = (*flag_arg)->value.lval;
-                       break;
-               default:
-                       WRONG_PARAM_COUNT;
-                       break;
-       }
        php_print_credits(flag);
        RETURN_TRUE;
 }
-
 /* }}} */
 
 /* {{{ proto string php_logo_guid(void)
    Return the special ID used to request the PHP logo in phpinfo screens*/
 PHP_FUNCTION(php_logo_guid)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1);
 }
 /* }}} */
@@ -529,6 +515,9 @@ PHP_FUNCTION(php_logo_guid)
    Return the special ID used to request the PHP logo in phpinfo screens*/
 PHP_FUNCTION(php_egg_logo_guid)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1);
 }
 /* }}} */
@@ -537,6 +526,9 @@ PHP_FUNCTION(php_egg_logo_guid)
    Return the special ID used to request the Zend logo in phpinfo screens*/
 PHP_FUNCTION(zend_logo_guid)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1);
 }
 /* }}} */
@@ -545,6 +537,9 @@ PHP_FUNCTION(zend_logo_guid)
    Return the current SAPI module name */
 PHP_FUNCTION(php_sapi_name)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        if (sapi_module.name) {
                RETURN_STRING(sapi_module.name, 1);
        } else {
@@ -558,6 +553,9 @@ PHP_FUNCTION(php_sapi_name)
    Return information about the system PHP was built on */
 PHP_FUNCTION(php_uname)
 {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
+               return;
+
        RETURN_STRING(php_get_uname(), 0);
 }