Skip to content

Commit

Permalink
Bugfix #27104 CLI/CGI SAPI module variable name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
helly25 committed Feb 11, 2004
1 parent c8c0e97 commit 1c00296
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
52 changes: 26 additions & 26 deletions sapi/cgi/cgi_main.c
Expand Up @@ -119,8 +119,8 @@ static pid_t pgroup;
#define PHP_MODE_LINT 4
#define PHP_MODE_STRIP 5

static char *optarg = NULL;
static int optind = 1;
static char *php_optarg = NULL;
static int php_optind = 1;

static const opt_struct OPTIONS[] = {
{'a', 0, "interactive"},
Expand Down Expand Up @@ -928,8 +928,8 @@ int main(int argc, char *argv[])
/* temporary locals */
int behavior=PHP_MODE_STANDARD;
int no_headers=0;
int orig_optind=optind;
char *orig_optarg=optarg;
int orig_optind=php_optind;
char *orig_optarg=php_optarg;
char *script_file=NULL;
zend_llist global_vars;
#if FORCE_CGI_REDIRECT
Expand Down Expand Up @@ -1018,10 +1018,10 @@ int main(int argc, char *argv[])
/* allow ini override for fastcgi */
#endif
) {
while ((c=php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0))!=-1) {
while ((c=php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) {
switch (c) {
case 'c':
cgi_sapi_module.php_ini_path_override = strdup(optarg);
cgi_sapi_module.php_ini_path_override = strdup(php_optarg);
break;
case 'n':
cgi_sapi_module.php_ini_ignore = 1;
Expand All @@ -1033,16 +1033,16 @@ int main(int argc, char *argv[])
server by accepting a bindpath parameter. */
case 'b':
if (!fastcgi) {
bindpath = strdup(optarg);
bindpath = strdup(php_optarg);
}
break;
#endif
#endif
}

}
optind = orig_optind;
optarg = orig_optarg;
php_optind = orig_optind;
php_optarg = orig_optarg;
}

#ifdef ZTS
Expand Down Expand Up @@ -1254,7 +1254,7 @@ consult the installation file that came with this distribution, or visit \n\
&& !fastcgi
#endif
) {
while ((c=php_getopt(argc, argv, OPTIONS, &optarg, &optind, 1))!=-1) {
while ((c=php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1))!=-1) {
switch (c) {
case 'h':
case '?':
Expand All @@ -1268,8 +1268,8 @@ consult the installation file that came with this distribution, or visit \n\
break;
}
}
optind = orig_optind;
optarg = orig_optarg;
php_optind = orig_optind;
php_optarg = orig_optarg;
}

#if PHP_FASTCGI
Expand Down Expand Up @@ -1319,7 +1319,7 @@ consult the installation file that came with this distribution, or visit \n\
exit(1);
}

while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0)) != -1) {
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
switch (c) {

case 'a': /* interactive mode */
Expand All @@ -1331,24 +1331,24 @@ consult the installation file that came with this distribution, or visit \n\
SG(options) |= SAPI_OPTION_NO_CHDIR;
break;
case 'd': /* define ini entries on command line */
define_command_line_ini_entry(optarg);
define_command_line_ini_entry(php_optarg);
break;

case 'e': /* enable extended info output */
CG(extended_info) = 1;
break;

case 'f': /* parse file */
script_file = estrdup(optarg);
script_file = estrdup(php_optarg);
no_headers = 1;
/* arguments after the file are considered script args */
SG(request_info).argc = argc - (optind-1);
SG(request_info).argv = &argv[optind-1];
SG(request_info).argc = argc - (php_optind-1);
SG(request_info).argv = &argv[php_optind-1];
break;

case 'g': /* define global variables on command line */
{
char *arg = estrdup(optarg);
char *arg = estrdup(php_optarg);

zend_llist_add_element(&global_vars, &arg);
}
Expand Down Expand Up @@ -1424,7 +1424,7 @@ consult the installation file that came with this distribution, or visit \n\
break;

case 'z': /* load extension file */
zend_load_extension(optarg);
zend_load_extension(php_optarg);
break;

default:
Expand All @@ -1442,12 +1442,12 @@ consult the installation file that came with this distribution, or visit \n\
SG(request_info).no_headers = 1;
}

if (!SG(request_info).path_translated && argc > optind) {
if (!SG(request_info).path_translated && argc > php_optind) {
/* arguments after the file are considered script args */
SG(request_info).argc = argc - optind;
SG(request_info).argv = &argv[optind];
SG(request_info).argc = argc - php_optind;
SG(request_info).argv = &argv[php_optind];
/* file is on command line, but not in -f opt */
SG(request_info).path_translated = estrdup(argv[optind++]);
SG(request_info).path_translated = estrdup(argv[php_optind++]);
}

/* all remaining arguments are part of the query string
Expand All @@ -1459,15 +1459,15 @@ consult the installation file that came with this distribution, or visit \n\
test.php "v1=test&v2=hello world!"
test.php v1=test "v2=hello world!"
*/
if (!SG(request_info).query_string && argc > optind) {
if (!SG(request_info).query_string && argc > php_optind) {
len = 0;
for (i = optind; i < argc; i++) {
for (i = php_optind; i < argc; i++) {
len += strlen(argv[i]) + 1;
}

s = malloc(len + 1); /* leak - but only for command line version, so ok */
*s = '\0'; /* we are pretending it came from the environment */
for (i = optind, len = 0; i < argc; i++) {
for (i = php_optind, len = 0; i < argc; i++) {
strcat(s, argv[i]);
if (i < (argc - 1)) {
strcat(s, PG(arg_separator).input);
Expand Down
60 changes: 30 additions & 30 deletions sapi/cli/php_cli.c
Expand Up @@ -89,8 +89,8 @@
#define PHP_MODE_CLI_DIRECT 6
#define PHP_MODE_PROCESS_STDIN 7

static char *optarg = NULL;
static int optind = 1;
static char *php_optarg = NULL;
static int php_optind = 1;

static const opt_struct OPTIONS[] = {
{'a', 0, "interactive"},
Expand Down Expand Up @@ -527,8 +527,8 @@ int main(int argc, char *argv[])
zend_file_handle file_handle;
/* temporary locals */
int behavior=PHP_MODE_STANDARD;
int orig_optind=optind;
char *orig_optarg=optarg;
int orig_optind=php_optind;
char *orig_optarg=php_optarg;
char *arg_free=NULL, **arg_excp=&arg_free;
char *script_file=NULL;
zend_llist global_vars;
Expand Down Expand Up @@ -594,18 +594,18 @@ int main(int argc, char *argv[])
#endif


while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0))!=-1) {
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0))!=-1) {
switch (c) {
case 'c':
cli_sapi_module.php_ini_path_override = strdup(optarg);
cli_sapi_module.php_ini_path_override = strdup(php_optarg);
break;
case 'n':
cli_sapi_module.php_ini_ignore = 1;
break;
}
}
optind = orig_optind;
optarg = orig_optarg;
php_optind = orig_optind;
php_optarg = orig_optarg;

cli_sapi_module.executable_location = argv[0];

Expand Down Expand Up @@ -649,11 +649,11 @@ int main(int argc, char *argv[])
INI_HARDCODED("output_buffering", "0");
INI_HARDCODED("max_execution_time", "0");

while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0)) != -1) {
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
switch (c) {

case 'd': /* define ini entries on command line */
define_command_line_ini_entry(optarg);
define_command_line_ini_entry(php_optarg);
break;

case 'h': /* help & quit */
Expand Down Expand Up @@ -708,9 +708,9 @@ int main(int argc, char *argv[])
/* Set some CLI defaults */
SG(options) |= SAPI_OPTION_NO_CHDIR;

optind = orig_optind;
optarg = orig_optarg;
while ((c = php_getopt(argc, argv, OPTIONS, &optarg, &optind, 0)) != -1) {
php_optind = orig_optind;
php_optarg = orig_optarg;
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
switch (c) {

case 'a': /* interactive mode */
Expand Down Expand Up @@ -738,7 +738,7 @@ int main(int argc, char *argv[])
break;
}
behavior=PHP_MODE_PROCESS_STDIN;
script_file = optarg;
script_file = php_optarg;
break;

case 'f': /* parse file */
Expand All @@ -749,12 +749,12 @@ int main(int argc, char *argv[])
param_error = "You can use -f only once.\n";
break;
}
script_file = optarg;
script_file = php_optarg;
break;

case 'g': /* define global variables on command line */
{
char *arg = estrdup(optarg);
char *arg = estrdup(php_optarg);

zend_llist_add_element(&global_vars, &arg);
}
Expand Down Expand Up @@ -792,7 +792,7 @@ int main(int argc, char *argv[])
break;
}
behavior=PHP_MODE_CLI_DIRECT;
exec_direct=optarg;
exec_direct=php_optarg;
break;

case 'R':
Expand All @@ -806,7 +806,7 @@ int main(int argc, char *argv[])
break;
}
behavior=PHP_MODE_PROCESS_STDIN;
exec_run=optarg;
exec_run=php_optarg;
break;

case 'B':
Expand All @@ -820,7 +820,7 @@ int main(int argc, char *argv[])
break;
}
behavior=PHP_MODE_PROCESS_STDIN;
exec_begin=optarg;
exec_begin=php_optarg;
break;

case 'E':
Expand All @@ -834,7 +834,7 @@ int main(int argc, char *argv[])
break;
}
behavior=PHP_MODE_PROCESS_STDIN;
exec_end=optarg;
exec_end=php_optarg;
break;

case 's': /* generate highlighted HTML from source */
Expand All @@ -854,7 +854,7 @@ int main(int argc, char *argv[])
break;

case 'z': /* load extension file */
zend_load_extension(optarg);
zend_load_extension(php_optarg);
break;
case 'H':
hide_argv = 1;
Expand All @@ -874,14 +874,14 @@ int main(int argc, char *argv[])
CG(interactive) = interactive;

/* only set script_file if not set already and not in direct mode and not at end of parameter list */
if (argc > optind
if (argc > php_optind
&& !script_file
&& behavior!=PHP_MODE_CLI_DIRECT
&& behavior!=PHP_MODE_PROCESS_STDIN
&& strcmp(argv[optind-1],"--"))
&& strcmp(argv[php_optind-1],"--"))
{
script_file=argv[optind];
optind++;
script_file=argv[php_optind];
php_optind++;
}
if (script_file) {
if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
Expand All @@ -903,12 +903,12 @@ int main(int argc, char *argv[])

/* before registering argv to module exchange the *new* argv[0] */
/* we can achieve this without allocating more memory */
SG(request_info).argc=argc-optind+1;
arg_excp = argv+optind-1;
arg_free = argv[optind-1];
SG(request_info).argc=argc-php_optind+1;
arg_excp = argv+php_optind-1;
arg_free = argv[php_optind-1];
SG(request_info).path_translated = file_handle.filename;
argv[optind-1] = file_handle.filename;
SG(request_info).argv=argv+optind-1;
argv[php_optind-1] = file_handle.filename;
SG(request_info).argv=argv+php_optind-1;

if (php_request_startup(TSRMLS_C)==FAILURE) {
*arg_excp = arg_free;
Expand Down

0 comments on commit 1c00296

Please sign in to comment.