Skip to content

Commit 86cc560

Browse files
committed
Add test to check mismatching zend_func_info entries
1 parent 1622d22 commit 86cc560

File tree

5 files changed

+117
-23
lines changed

5 files changed

+117
-23
lines changed

ext/opcache/tests/func_info.phpt

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
$extensions = [
13+
"standard",
14+
"date",
15+
"pcre",
16+
"mysqli",
17+
"curl",
18+
"mbstring",
19+
"iconv",
20+
"json",
21+
"xml",
22+
"zlib",
23+
"hash",
24+
"sodium",
25+
"session",
26+
"pgsql",
27+
"bcmath",
28+
"exif",
29+
"filter",
30+
"gettext",
31+
"gd",
32+
"spl",
33+
];
34+
35+
$contents = "<?php\n";
36+
37+
foreach ($extensions as $extension) {
38+
try {
39+
$reflectionExtension = new ReflectionExtension($extension);
40+
41+
foreach ($reflectionExtension->getFunctions() as $function) {
42+
$contents .= "try {\n";
43+
$contents .= " {$function->getName()}(null, null, null, null, null, null, null, null);\n";
44+
$contents .= "} catch (ArgumentCountError|Error) {\n";
45+
$contents .= "}\n";
46+
}
47+
} catch (ReflectionException) {
48+
}
49+
}
50+
51+
file_put_contents("func_info_generated.php", $contents);
52+
53+
set_error_handler(
54+
function (string $code, string $message) {
55+
return true;
56+
},
57+
E_NOTICE | E_WARNING
58+
);
59+
60+
require_once("func_info_generated.php");
61+
62+
?>
63+
--CLEAN--
64+
<?php
65+
66+
unlink("func_info_generated.php");
67+
68+
?>
69+
--EXPECT--
70+
NULL
71+
NULL
72+
NULL
73+
NULL
74+
NULL
75+
NULL
76+
NULL
77+
NULL
78+
NULL
79+
NULL
80+
NULL
81+
NULL
82+
NULL
83+
NULL
84+
NULL
85+
NULL

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)