Skip to content

Commit 6ddab74

Browse files
authored
sapi: Fix some variable shadowing (#16485)
sapi_module, mime_type_map, zend_extensions, php_cgi_globals, and phpdbg_globals are true globals which are being shadowed
1 parent b6f59d2 commit 6ddab74

File tree

7 files changed

+66
-64
lines changed

7 files changed

+66
-64
lines changed

sapi/cgi/cgi_main.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,9 @@ static int sapi_cgi_deactivate(void)
968968
return SUCCESS;
969969
}
970970

971-
static int php_cgi_startup(sapi_module_struct *sapi_module)
971+
static int php_cgi_startup(sapi_module_struct *sapi_module_ptr)
972972
{
973-
return php_module_startup(sapi_module, &cgi_module_entry);
973+
return php_module_startup(sapi_module_ptr, &cgi_module_entry);
974974
}
975975

976976
/* {{{ sapi_module_struct cgi_sapi_module */
@@ -1518,23 +1518,23 @@ PHP_INI_BEGIN()
15181518
PHP_INI_END()
15191519

15201520
/* {{{ php_cgi_globals_ctor */
1521-
static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals)
1521+
static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals_ptr)
15221522
{
15231523
#if defined(ZTS) && defined(PHP_WIN32)
15241524
ZEND_TSRMLS_CACHE_UPDATE();
15251525
#endif
1526-
php_cgi_globals->rfc2616_headers = 0;
1527-
php_cgi_globals->nph = 0;
1528-
php_cgi_globals->check_shebang_line = 1;
1529-
php_cgi_globals->force_redirect = 1;
1530-
php_cgi_globals->redirect_status_env = NULL;
1531-
php_cgi_globals->fix_pathinfo = 1;
1532-
php_cgi_globals->discard_path = 0;
1533-
php_cgi_globals->fcgi_logging = 1;
1526+
php_cgi_globals_ptr->rfc2616_headers = 0;
1527+
php_cgi_globals_ptr->nph = 0;
1528+
php_cgi_globals_ptr->check_shebang_line = 1;
1529+
php_cgi_globals_ptr->force_redirect = 1;
1530+
php_cgi_globals_ptr->redirect_status_env = NULL;
1531+
php_cgi_globals_ptr->fix_pathinfo = 1;
1532+
php_cgi_globals_ptr->discard_path = 0;
1533+
php_cgi_globals_ptr->fcgi_logging = 1;
15341534
#ifdef PHP_WIN32
1535-
php_cgi_globals->impersonate = 0;
1535+
php_cgi_globals_ptr->impersonate = 0;
15361536
#endif
1537-
zend_hash_init(&php_cgi_globals->user_config_cache, 8, NULL, user_config_cache_entry_dtor, 1);
1537+
zend_hash_init(&php_cgi_globals_ptr->user_config_cache, 8, NULL, user_config_cache_entry_dtor, 1);
15381538
}
15391539
/* }}} */
15401540

@@ -2548,11 +2548,11 @@ consult the installation file that came with this distribution, or visit \n\
25482548
break;
25492549
case PHP_MODE_HIGHLIGHT:
25502550
{
2551-
zend_syntax_highlighter_ini syntax_highlighter_ini;
2551+
zend_syntax_highlighter_ini default_syntax_highlighter_ini;
25522552

25532553
if (open_file_for_scanning(&file_handle) == SUCCESS) {
2554-
php_get_highlight_struct(&syntax_highlighter_ini);
2555-
zend_highlight(&syntax_highlighter_ini);
2554+
php_get_highlight_struct(&default_syntax_highlighter_ini);
2555+
zend_highlight(&default_syntax_highlighter_ini);
25562556
}
25572557
}
25582558
break;

sapi/cli/php_cli.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_c
392392
}
393393
/* }}} */
394394

395-
static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */
395+
static int php_cli_startup(sapi_module_struct *sapi_module_ptr) /* {{{ */
396396
{
397-
return php_module_startup(sapi_module, NULL);
397+
return php_module_startup(sapi_module_ptr, NULL);
398398
}
399399
/* }}} */
400400

@@ -951,11 +951,11 @@ static int do_cli(int argc, char **argv) /* {{{ */
951951
break;
952952
case PHP_CLI_MODE_HIGHLIGHT:
953953
{
954-
zend_syntax_highlighter_ini syntax_highlighter_ini;
954+
zend_syntax_highlighter_ini default_syntax_highlighter_ini;
955955

956956
if (open_file_for_scanning(&file_handle) == SUCCESS) {
957-
php_get_highlight_struct(&syntax_highlighter_ini);
958-
zend_highlight(&syntax_highlighter_ini);
957+
php_get_highlight_struct(&default_syntax_highlighter_ini);
958+
zend_highlight(&default_syntax_highlighter_ini);
959959
}
960960
goto out;
961961
}
@@ -1155,7 +1155,7 @@ int main(int argc, char *argv[])
11551155
char *ini_path_override = NULL;
11561156
struct php_ini_builder ini_builder;
11571157
int ini_ignore = 0;
1158-
sapi_module_struct *sapi_module = &cli_sapi_module;
1158+
sapi_module_struct *sapi_module_ptr = &cli_sapi_module;
11591159

11601160
/*
11611161
* Do not move this initialization. It needs to happen before argv is used
@@ -1234,7 +1234,7 @@ int main(int argc, char *argv[])
12341234
break;
12351235
#ifndef PHP_CLI_WIN32_NO_CONSOLE
12361236
case 'S':
1237-
sapi_module = &cli_server_sapi_module;
1237+
sapi_module_ptr = &cli_server_sapi_module;
12381238
cli_server_sapi_module.additional_functions = server_additional_functions;
12391239
break;
12401240
#endif
@@ -1247,7 +1247,7 @@ int main(int argc, char *argv[])
12471247
exit_status = 1;
12481248
goto out;
12491249
case 'i': case 'v': case 'm':
1250-
sapi_module = &cli_sapi_module;
1250+
sapi_module_ptr = &cli_sapi_module;
12511251
goto exit_loop;
12521252
case 'e': /* enable extended info output */
12531253
use_extended_info = 1;
@@ -1256,25 +1256,25 @@ int main(int argc, char *argv[])
12561256
}
12571257
exit_loop:
12581258

1259-
sapi_module->ini_defaults = sapi_cli_ini_defaults;
1260-
sapi_module->php_ini_path_override = ini_path_override;
1261-
sapi_module->phpinfo_as_text = 1;
1262-
sapi_module->php_ini_ignore_cwd = 1;
1263-
sapi_startup(sapi_module);
1259+
sapi_module_ptr->ini_defaults = sapi_cli_ini_defaults;
1260+
sapi_module_ptr->php_ini_path_override = ini_path_override;
1261+
sapi_module_ptr->phpinfo_as_text = 1;
1262+
sapi_module_ptr->php_ini_ignore_cwd = 1;
1263+
sapi_startup(sapi_module_ptr);
12641264
sapi_started = 1;
12651265

1266-
sapi_module->php_ini_ignore = ini_ignore;
1266+
sapi_module_ptr->php_ini_ignore = ini_ignore;
12671267

1268-
sapi_module->executable_location = argv[0];
1268+
sapi_module_ptr->executable_location = argv[0];
12691269

1270-
if (sapi_module == &cli_sapi_module) {
1270+
if (sapi_module_ptr == &cli_sapi_module) {
12711271
php_ini_builder_prepend_literal(&ini_builder, HARDCODED_INI);
12721272
}
12731273

1274-
sapi_module->ini_entries = php_ini_builder_finish(&ini_builder);
1274+
sapi_module_ptr->ini_entries = php_ini_builder_finish(&ini_builder);
12751275

12761276
/* startup after we get the above ini override so we get things right */
1277-
if (sapi_module->startup(sapi_module) == FAILURE) {
1277+
if (sapi_module_ptr->startup(sapi_module_ptr) == FAILURE) {
12781278
/* there is no way to see if we must call zend_ini_deactivate()
12791279
* since we cannot check if EG(ini_directives) has been initialized
12801280
* because the executor's constructor does not set initialize it.
@@ -1305,7 +1305,7 @@ int main(int argc, char *argv[])
13051305

13061306
zend_first_try {
13071307
#ifndef PHP_CLI_WIN32_NO_CONSOLE
1308-
if (sapi_module == &cli_sapi_module) {
1308+
if (sapi_module_ptr == &cli_sapi_module) {
13091309
#endif
13101310
exit_status = do_cli(argc, argv);
13111311
#ifndef PHP_CLI_WIN32_NO_CONSOLE

sapi/cli/php_cli_server.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ const zend_function_entry server_additional_functions[] = {
510510
PHP_FE_END
511511
};
512512

513-
static int sapi_cli_server_startup(sapi_module_struct *sapi_module) /* {{{ */
513+
static int sapi_cli_server_startup(sapi_module_struct *sapi_module_ptr) /* {{{ */
514514
{
515-
return php_module_startup(sapi_module, &cli_server_module_entry);
515+
return php_module_startup(sapi_module_ptr, &cli_server_module_entry);
516516
} /* }}} */
517517

518518
static size_t sapi_cli_server_ub_write(const char *str, size_t str_length) /* {{{ */
@@ -2353,14 +2353,14 @@ static zend_result php_cli_server_dispatch(php_cli_server *server, php_cli_serve
23532353
}
23542354
/* }}} */
23552355

2356-
static void php_cli_server_mime_type_ctor(php_cli_server *server, const php_cli_server_ext_mime_type_pair *mime_type_map) /* {{{ */
2356+
static void php_cli_server_mime_type_ctor(php_cli_server *server, const php_cli_server_ext_mime_type_pair *mime_type_map_ptr) /* {{{ */
23572357
{
23582358
const php_cli_server_ext_mime_type_pair *pair;
23592359

23602360
zend_hash_init(&server->extension_mime_types, 0, NULL, NULL, 1);
23612361
GC_MAKE_PERSISTENT_LOCAL(&server->extension_mime_types);
23622362

2363-
for (pair = mime_type_map; pair->ext; pair++) {
2363+
for (pair = mime_type_map_ptr; pair->ext; pair++) {
23642364
size_t ext_len = strlen(pair->ext);
23652365
zend_hash_str_add_ptr(&server->extension_mime_types, pair->ext, ext_len, (void*)pair->mime_type);
23662366
}
@@ -2396,7 +2396,7 @@ static void php_cli_server_dtor(php_cli_server *server) /* {{{ */
23962396
do {
23972397
if (waitpid(php_cli_server_workers[php_cli_server_worker],
23982398
&php_cli_server_worker_status,
2399-
0) == FAILURE) {
2399+
0) == (pid_t) -1) {
24002400
/* an extremely bad thing happened */
24012401
break;
24022402
}

sapi/phpdbg/phpdbg.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,8 @@ int main(int argc, char **argv) /* {{{ */
11241124
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
11251125
char *sapi_name;
11261126
struct php_ini_builder ini_builder;
1127-
char **zend_extensions = NULL;
1128-
zend_ulong zend_extensions_len = 0L;
1127+
char **zend_extensions_list = NULL;
1128+
size_t zend_extensions_len = 0;
11291129
bool ini_ignore;
11301130
char *ini_override;
11311131
char *exec = NULL;
@@ -1177,8 +1177,6 @@ int main(int argc, char **argv) /* {{{ */
11771177
php_ini_builder_init(&ini_builder);
11781178
ini_ignore = 0;
11791179
ini_override = NULL;
1180-
zend_extensions = NULL;
1181-
zend_extensions_len = 0L;
11821180
init_file = NULL;
11831181
init_file_len = 0;
11841182
init_file_default = 1;
@@ -1216,10 +1214,12 @@ int main(int argc, char **argv) /* {{{ */
12161214

12171215
case 'z':
12181216
zend_extensions_len++;
1219-
if (zend_extensions) {
1220-
zend_extensions = realloc(zend_extensions, sizeof(char*) * zend_extensions_len);
1221-
} else zend_extensions = malloc(sizeof(char*) * zend_extensions_len);
1222-
zend_extensions[zend_extensions_len-1] = strdup(php_optarg);
1217+
if (zend_extensions_list) {
1218+
zend_extensions_list = realloc(zend_extensions_list, sizeof(char*) * zend_extensions_len);
1219+
} else {
1220+
zend_extensions_list = malloc(sizeof(char*) * zend_extensions_len);
1221+
}
1222+
zend_extensions_list[zend_extensions_len-1] = strdup(php_optarg);
12231223
break;
12241224

12251225
/* begin phpdbg options */
@@ -1316,19 +1316,19 @@ int main(int argc, char **argv) /* {{{ */
13161316
php_ini_builder_prepend_literal(&ini_builder, phpdbg_ini_hardcoded);
13171317

13181318
if (zend_extensions_len) {
1319-
zend_ulong zend_extension = 0L;
1319+
size_t zend_extension_index = 0;
13201320

1321-
while (zend_extension < zend_extensions_len) {
1322-
const char *ze = zend_extensions[zend_extension];
1321+
while (zend_extension_index < zend_extensions_len) {
1322+
const char *ze = zend_extensions_list[zend_extension_index];
13231323
size_t ze_len = strlen(ze);
13241324

13251325
php_ini_builder_unquoted(&ini_builder, "zend_extension", strlen("zend_extension"), ze, ze_len);
13261326

1327-
free(zend_extensions[zend_extension]);
1328-
zend_extension++;
1327+
free(zend_extensions_list[zend_extension_index]);
1328+
zend_extension_index++;
13291329
}
13301330

1331-
free(zend_extensions);
1331+
free(zend_extensions_list);
13321332
}
13331333

13341334
phpdbg->ini_entries = php_ini_builder_finish(&ini_builder);

sapi/phpdbg/phpdbg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input);
193193

194194
#define phpdbg_try_access \
195195
{ \
196+
ZEND_DIAGNOSTIC_IGNORED_START("-Wshadow") \
196197
JMP_BUF *__orig_bailout = PHPDBG_G(sigsegv_bailout); \
197198
JMP_BUF __bailout; \
199+
ZEND_DIAGNOSTIC_IGNORED_END \
198200
\
199201
PHPDBG_G(sigsegv_bailout) = &__bailout; \
200202
if (SETJMP(__bailout) == 0) {

sapi/phpdbg/phpdbg_bp.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,28 +1510,28 @@ PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */
15101510
phpdbg_out(SEPARATE "\n");
15111511
phpdbg_out("Opline Breakpoints:\n");
15121512
ZEND_HASH_MAP_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], brake) {
1513-
const char *type;
1513+
const char *str_type;
15141514
switch (brake->type) {
15151515
case PHPDBG_BREAK_METHOD_OPLINE:
1516-
type = "method";
1516+
str_type = "method";
15171517
goto print_opline;
15181518
case PHPDBG_BREAK_FUNCTION_OPLINE:
1519-
type = "function";
1519+
str_type = "function";
15201520
goto print_opline;
15211521
case PHPDBG_BREAK_FILE_OPLINE:
1522-
type = "method";
1522+
str_type = "method";
15231523

15241524
print_opline: {
15251525
if (brake->type == PHPDBG_BREAK_METHOD_OPLINE) {
1526-
type = "method";
1526+
str_type = "method";
15271527
} else if (brake->type == PHPDBG_BREAK_FUNCTION_OPLINE) {
1528-
type = "function";
1528+
str_type = "function";
15291529
} else if (brake->type == PHPDBG_BREAK_FILE_OPLINE) {
1530-
type = "file";
1530+
str_type = "file";
15311531
}
15321532

15331533
phpdbg_writeln("#%d\t\t#"ZEND_ULONG_FMT"\t\t(%s breakpoint)%s",
1534-
brake->id, brake->opline, type,
1534+
brake->id, brake->opline, str_type,
15351535
((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
15361536
} break;
15371537

sapi/phpdbg/phpdbg_watch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context) {
310310
# if defined(__GNUC__) && !defined(__clang__)
311311
__attribute__((no_sanitize_address))
312312
# endif
313-
void *phpdbg_watchpoint_userfaultfd_thread(void *phpdbg_globals) {
313+
void *phpdbg_watchpoint_userfaultfd_thread(void *phpdbg_globals_ptr) {
314314
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
315-
zend_phpdbg_globals *globals = (zend_phpdbg_globals *) phpdbg_globals;
315+
zend_phpdbg_globals *globals = (zend_phpdbg_globals *) phpdbg_globals_ptr;
316316

317317
struct uffd_msg fault_msg = {0};
318318
while (read(globals->watch_userfaultfd, &fault_msg, sizeof(fault_msg)) == sizeof(fault_msg)) {

0 commit comments

Comments
 (0)