Skip to content

Commit f2e0b2a

Browse files
committed
Add tests to check mismatching function signatures
1 parent 1622d22 commit f2e0b2a

File tree

6 files changed

+112
-23
lines changed

6 files changed

+112
-23
lines changed

Zend/tests/arginfo_zpp_mismatch.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Test that there is no arginfo/zpp mismatch
3+
--FILE--
4+
<?php
5+
6+
$contents = "<?php\n";
7+
8+
foreach (get_defined_functions()["internal"] as $function) {
9+
$contents .= "try {";
10+
$contents .= " {$function}(null, null, null, null, null, null, null, null);\n";
11+
$contents .= "} catch (ArgumentCountError|Error) {";
12+
$contents .= "}";
13+
}
14+
15+
file_put_contents("arginfo_zpp_mismatch_generated.php", $contents);
16+
17+
set_error_handler(
18+
function (string $code, string $message) {
19+
return true;
20+
},
21+
E_NOTICE | E_WARNING
22+
);
23+
24+
require_once("arginfo_zpp_mismatch_generated.php");
25+
26+
?>
27+
--CLEAN--
28+
<?php
29+
30+
unlink("arginfo_zpp_mismatch_generated.php");
31+
32+
?>
33+
--EXPECT--
34+
NULL
35+
NULL
36+
NULL
37+
NULL
38+
NULL
39+
NULL
40+
NULL
41+
NULL
42+
NULL
43+
NULL
44+
NULL
45+
NULL
46+
NULL
47+
NULL
48+
NULL
49+
NULL

ext/opcache/tests/func_info.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Test that return types in zend_func_info.c match return types in stubs
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--SKIPIF--
8+
<?php require_once('skipif.inc'); ?>
9+
--FILE--
10+
<?php
11+
12+
$contents = "<?php\n";
13+
14+
$contents .= "function test() {\n";
15+
foreach (get_defined_functions()["internal"] as $function) {
16+
$contents .= " {$function}();\n";
17+
}
18+
$contents .= "}\n";
19+
20+
file_put_contents("func_info_generated.php", $contents);
21+
22+
require_once("func_info_generated.php");
23+
24+
?>
25+
--CLEAN--
26+
<?php
27+
28+
unlink("func_info_generated.php");
29+
30+
?>
31+
--EXPECT--

ext/session/session.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,24 +1917,28 @@ PHP_FUNCTION(session_module_name)
19171917
}
19181918
/* }}} */
19191919

1920-
/* {{{ proto bool session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid)
1921-
Sets user-level functions */
1922-
PHP_FUNCTION(session_set_save_handler)
1923-
{
1924-
zval *args = NULL;
1925-
int i, num_args, argc = ZEND_NUM_ARGS();
1926-
zend_string *ini_name, *ini_val;
1927-
1920+
static int save_handler_check_session() {
19281921
if (PS(session_status) == php_session_active) {
19291922
php_error_docref(NULL, E_WARNING, "Cannot change save handler when session is active");
1930-
RETURN_FALSE;
1923+
return FAILURE;
19311924
}
19321925

19331926
if (SG(headers_sent)) {
19341927
php_error_docref(NULL, E_WARNING, "Cannot change save handler when headers already sent");
1935-
RETURN_FALSE;
1928+
return FAILURE;
19361929
}
19371930

1931+
return SUCCESS;
1932+
}
1933+
1934+
/* {{{ proto bool session_set_save_handler(string open, string close, string read, string write, string destroy, string gc, string create_sid)
1935+
Sets user-level functions */
1936+
PHP_FUNCTION(session_set_save_handler)
1937+
{
1938+
zval *args = NULL;
1939+
int i, num_args, argc = ZEND_NUM_ARGS();
1940+
zend_string *ini_name, *ini_val;
1941+
19381942
if (argc > 0 && argc <= 2) {
19391943
zval *obj = NULL;
19401944
zend_string *func_name;
@@ -1945,6 +1949,10 @@ PHP_FUNCTION(session_set_save_handler)
19451949
RETURN_THROWS();
19461950
}
19471951

1952+
if (save_handler_check_session() == FAILURE) {
1953+
RETURN_FALSE;
1954+
}
1955+
19481956
/* For compatibility reason, implemented interface is not checked */
19491957
/* Find implemented methods - SessionHandlerInterface */
19501958
i = 0;
@@ -2047,6 +2055,10 @@ PHP_FUNCTION(session_set_save_handler)
20472055
RETURN_THROWS();
20482056
}
20492057

2058+
if (save_handler_check_session() == FAILURE) {
2059+
RETURN_FALSE;
2060+
}
2061+
20502062
/* remove shutdown function */
20512063
remove_user_shutdown_function("session_shutdown", sizeof("session_shutdown") - 1);
20522064

ext/standard/basic_functions.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,14 +2539,14 @@ PHP_FUNCTION(is_uploaded_file)
25392539
char *path;
25402540
size_t path_len;
25412541

2542-
if (!SG(rfc1867_uploaded_files)) {
2543-
RETURN_FALSE;
2544-
}
2545-
25462542
ZEND_PARSE_PARAMETERS_START(1, 1)
25472543
Z_PARAM_PATH(path, path_len)
25482544
ZEND_PARSE_PARAMETERS_END();
25492545

2546+
if (!SG(rfc1867_uploaded_files)) {
2547+
RETURN_FALSE;
2548+
}
2549+
25502550
if (zend_hash_str_exists(SG(rfc1867_uploaded_files), path, path_len)) {
25512551
RETURN_TRUE;
25522552
} else {
@@ -2567,15 +2567,15 @@ PHP_FUNCTION(move_uploaded_file)
25672567
int oldmask; int ret;
25682568
#endif
25692569

2570-
if (!SG(rfc1867_uploaded_files)) {
2571-
RETURN_FALSE;
2572-
}
2573-
25742570
ZEND_PARSE_PARAMETERS_START(2, 2)
25752571
Z_PARAM_STRING(path, path_len)
25762572
Z_PARAM_PATH(new_path, new_path_len)
25772573
ZEND_PARSE_PARAMETERS_END();
25782574

2575+
if (!SG(rfc1867_uploaded_files)) {
2576+
RETURN_FALSE;
2577+
}
2578+
25792579
if (!zend_hash_str_exists(SG(rfc1867_uploaded_files), path, path_len)) {
25802580
RETURN_FALSE;
25812581
}

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function parse_ini_file(string $filename, bool $process_sections = false, int $s
357357
function parse_ini_string(string $ini_string, bool $process_sections = false, int $scanner_mode = INI_SCANNER_NORMAL): array|false {}
358358

359359
#if ZEND_DEBUG
360-
function config_get_hash(string $ini_string, bool $process_sections = false, int $scanner_mode = INI_SCANNER_NORMAL): array {}
360+
function config_get_hash(): array {}
361361
#endif
362362

363363
#ifdef HAVE_GETLOADAVG

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_parse_ini_string, 0, 1, MAY_BE_A
578578
ZEND_END_ARG_INFO()
579579

580580
#if ZEND_DEBUG
581-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_config_get_hash, 0, 1, IS_ARRAY, 0)
582-
ZEND_ARG_TYPE_INFO(0, ini_string, IS_STRING, 0)
583-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, process_sections, _IS_BOOL, 0, "false")
584-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, scanner_mode, IS_LONG, 0, "INI_SCANNER_NORMAL")
581+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_config_get_hash, 0, 0, IS_ARRAY, 0)
585582
ZEND_END_ARG_INFO()
586583
#endif
587584

0 commit comments

Comments
 (0)