Skip to content

Commit 8c497f0

Browse files
committed
We don't consistently check for args passed to functions that don't
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.
1 parent 3f505f8 commit 8c497f0

File tree

15 files changed

+91
-44
lines changed

15 files changed

+91
-44
lines changed

ext/curl/curl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ static void curl_free_slist(void **slist)
504504
Return the CURL version string. */
505505
PHP_FUNCTION(curl_version)
506506
{
507+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
508+
return;
509+
507510
RETURN_STRING(curl_version(), 1);
508511
}
509512
/* }}} */

ext/db/db.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ PHP_MINFO_FUNCTION(db)
252252
Describes the dbm-compatible library being used */
253253
PHP_FUNCTION(dblist)
254254
{
255+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
256+
return;
257+
255258
char *str = php_get_info_db();
256259
RETURN_STRING(str, 1);
257260
}

ext/domxml/php_domxml.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,9 @@ PHP_FUNCTION(xmltree)
24322432
Initializing XPath environment */
24332433
PHP_FUNCTION(xpath_init)
24342434
{
2435+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
2436+
return;
2437+
24352438
xmlXPathInit();
24362439
RETURN_TRUE;
24372440
}

ext/fdf/fdf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ PHP_FUNCTION(fdf_create)
209209
FDFDoc fdf;
210210
FDFErc err;
211211

212+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
213+
return;
214+
212215
err = FDFCreate(&fdf);
213216

214217
if(err != FDFErcOK || !fdf) {

ext/gd/gd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,9 @@ PHP_FUNCTION(imagetypes)
931931
#ifdef HAVE_GD_XPM
932932
ret |= 16;
933933
#endif
934+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
935+
return;
936+
934937
RETURN_LONG(ret);
935938
}
936939
/* }}} */

ext/hyperwave/hw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,9 @@ PHP_FUNCTION(hw_errormsg)
13311331
Returns object id of root collection */
13321332
PHP_FUNCTION(hw_root)
13331333
{
1334+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
1335+
return;
1336+
13341337
return_value->value.lval = 0;
13351338
return_value->type = IS_LONG;
13361339
}

ext/interbase/interbase.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ typedef struct {
236236
Return error message */
237237
PHP_FUNCTION(ibase_errmsg)
238238
{
239+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
240+
return;
241+
239242
if (IBG(errmsg[0])) {
240243
RETURN_STRING(IBG(errmsg), 1);
241244
}

ext/mhash/mhash.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ static PHP_MINIT_FUNCTION(mhash)
8383
Gets the number of available hashes */
8484
PHP_FUNCTION(mhash_count)
8585
{
86+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
87+
return;
88+
8689
RETURN_LONG(mhash_count());
8790
}
8891

ext/odbc/php_odbc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,10 @@ PHP_FUNCTION(odbc_close_all)
710710
int type;
711711
int i;
712712
int nument;
713-
713+
714+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
715+
return;
716+
714717
nument = zend_hash_next_free_element(&EG(regular_list));
715718

716719
/* Loop through list and close all statements */

ext/sablot/sablot.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ PHP_FUNCTION(xslt_output_endtransform)
291291
char *tRes = NULL,
292292
*buffer = NULL;
293293
int ret = 0;
294-
294+
295+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
296+
return;
297+
295298
/**
296299
* Make sure that we don't have more than one output buffer going on
297300
* at the same time.
@@ -556,7 +559,10 @@ PHP_FUNCTION(xslt_create)
556559
php_sablot *handle;
557560
SablotHandle p;
558561
int ret;
559-
562+
563+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
564+
return;
565+
560566
ret = SablotCreateProcessor(&p);
561567

562568
if (ret) {

ext/session/session.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ PHP_FUNCTION(session_encode)
12291229
int len;
12301230
char *enc;
12311231

1232+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
1233+
return;
1234+
12321235
enc = php_session_encode(&len TSRMLS_CC);
12331236
RETVAL_STRINGL(enc, len, 0);
12341237
}
@@ -1253,6 +1256,7 @@ PHP_FUNCTION(session_decode)
12531256
Begin session - reinitializes freezed variables, registers browsers etc */
12541257
PHP_FUNCTION(session_start)
12551258
{
1259+
/* skipping check for non-zero args for performance reasons here ?*/
12561260
php_session_start(TSRMLS_C);
12571261
RETURN_TRUE;
12581262
}
@@ -1262,6 +1266,9 @@ PHP_FUNCTION(session_start)
12621266
Destroy the current session and all data associated with it */
12631267
PHP_FUNCTION(session_destroy)
12641268
{
1269+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
1270+
return;
1271+
12651272
if (php_session_destroy(TSRMLS_C) == SUCCESS) {
12661273
RETURN_TRUE;
12671274
} else {

ext/snmp/snmp.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ PHP_FUNCTION(snmprealwalk)
402402
Return the current status of quick_print */
403403
PHP_FUNCTION(snmp_get_quick_print)
404404
{
405+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
406+
return;
407+
405408
RETURN_LONG(snmp_get_quick_print() ? 1 : 0);
406409
}
407410
/* }}} */
@@ -410,12 +413,12 @@ PHP_FUNCTION(snmp_get_quick_print)
410413
Return all objects including their respective object id withing the specified one */
411414
PHP_FUNCTION(snmp_set_quick_print)
412415
{
413-
zval **a1;
414-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &a1) == FAILURE) {
415-
WRONG_PARAM_COUNT;
416-
}
417-
convert_to_long_ex(a1);
418-
snmp_set_quick_print((int)(*a1)->value.lval);
416+
int argc = ZEND_NUM_ARGS();
417+
long a1;
418+
419+
if (zend_parse_parameters(argc, "l", &a1) == FAILURE)
420+
return;
421+
snmp_set_quick_print((int)a1);
419422
}
420423
/* }}} */
421424

ext/sockets/sockets.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ PHP_FUNCTION(socket_fd_alloc)
397397
{
398398
php_fd_set *php_fd;
399399

400+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
401+
return;
402+
400403
php_fd = (php_fd_set*)emalloc(sizeof(php_fd_set));
401404

402405
FD_ZERO(&(php_fd->set));

ext/standard/basic_functions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,9 @@ PHP_FUNCTION(settype)
13161316
Get the name of the owner of the current PHP script */
13171317
PHP_FUNCTION(get_current_user)
13181318
{
1319+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
1320+
return;
1321+
13191322
RETURN_STRING(php_get_current_user(), 1);
13201323
}
13211324
/* }}} */

ext/standard/info.c

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -455,26 +455,16 @@ void register_phpinfo_constants(INIT_FUNC_ARGS)
455455
Output a page of useful information about PHP and the current request */
456456
PHP_FUNCTION(phpinfo)
457457
{
458-
int flag;
459-
zval **flag_arg;
458+
int argc = ZEND_NUM_ARGS();
459+
long flag;
460460

461+
if (zend_parse_parameters(argc, "|l", &flag) == FAILURE)
462+
return;
461463

462-
switch (ZEND_NUM_ARGS()) {
463-
case 0:
464-
flag = 0xFFFFFFFF;
465-
break;
466-
case 1:
467-
if (zend_get_parameters_ex(1, &flag_arg)==FAILURE) {
468-
RETURN_FALSE;
469-
}
470-
convert_to_long_ex(flag_arg);
471-
flag = (*flag_arg)->value.lval;
472-
break;
473-
default:
474-
WRONG_PARAM_COUNT;
475-
break;
464+
if(!argc) {
465+
flag = 0xFFFFFFFF;
476466
}
477-
php_print_info(flag TSRMLS_CC);
467+
478468
RETURN_TRUE;
479469
}
480470

@@ -484,6 +474,9 @@ PHP_FUNCTION(phpinfo)
484474
Return the current PHP version */
485475
PHP_FUNCTION(phpversion)
486476
{
477+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
478+
return;
479+
487480
RETURN_STRING(PHP_VERSION, 1);
488481
}
489482
/* }}} */
@@ -492,35 +485,28 @@ PHP_FUNCTION(phpversion)
492485
Prints the list of people who've contributed to the PHP project */
493486
PHP_FUNCTION(phpcredits)
494487
{
495-
int flag;
496-
zval **flag_arg;
488+
int argc = ZEND_NUM_ARGS();
489+
long flag;
497490

491+
if (zend_parse_parameters(argc, "|l", &flag) == FAILURE)
492+
return;
493+
494+
if(!argc) {
495+
flag = 0xFFFFFFFF;
496+
}
498497

499-
switch (ZEND_NUM_ARGS()) {
500-
case 0:
501-
flag = 0xFFFFFFFF;
502-
break;
503-
case 1:
504-
if (zend_get_parameters_ex(1, &flag_arg)==FAILURE) {
505-
RETURN_FALSE;
506-
}
507-
convert_to_long_ex(flag_arg);
508-
flag = (*flag_arg)->value.lval;
509-
break;
510-
default:
511-
WRONG_PARAM_COUNT;
512-
break;
513-
}
514498
php_print_credits(flag);
515499
RETURN_TRUE;
516500
}
517-
518501
/* }}} */
519502

520503
/* {{{ proto string php_logo_guid(void)
521504
Return the special ID used to request the PHP logo in phpinfo screens*/
522505
PHP_FUNCTION(php_logo_guid)
523506
{
507+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
508+
return;
509+
524510
RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1);
525511
}
526512
/* }}} */
@@ -529,6 +515,9 @@ PHP_FUNCTION(php_logo_guid)
529515
Return the special ID used to request the PHP logo in phpinfo screens*/
530516
PHP_FUNCTION(php_egg_logo_guid)
531517
{
518+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
519+
return;
520+
532521
RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1);
533522
}
534523
/* }}} */
@@ -537,6 +526,9 @@ PHP_FUNCTION(php_egg_logo_guid)
537526
Return the special ID used to request the Zend logo in phpinfo screens*/
538527
PHP_FUNCTION(zend_logo_guid)
539528
{
529+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
530+
return;
531+
540532
RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1);
541533
}
542534
/* }}} */
@@ -545,6 +537,9 @@ PHP_FUNCTION(zend_logo_guid)
545537
Return the current SAPI module name */
546538
PHP_FUNCTION(php_sapi_name)
547539
{
540+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
541+
return;
542+
548543
if (sapi_module.name) {
549544
RETURN_STRING(sapi_module.name, 1);
550545
} else {
@@ -558,6 +553,9 @@ PHP_FUNCTION(php_sapi_name)
558553
Return information about the system PHP was built on */
559554
PHP_FUNCTION(php_uname)
560555
{
556+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE)
557+
return;
558+
561559
RETURN_STRING(php_get_uname(), 0);
562560
}
563561

0 commit comments

Comments
 (0)