summaryrefslogtreecommitdiff
path: root/sapi/cli/php_cli.c
diff options
context:
space:
mode:
authorFelipe Pena <felipe@php.net>2011-06-25 13:15:24 +0000
committerFelipe Pena <felipe@php.net>2011-06-25 13:15:24 +0000
commitdc467a70d302cd2554a647cacef7f4145b4910ba (patch)
treef6be39c280b2b83f6d390dbf9d1407a0325c16f0 /sapi/cli/php_cli.c
parent213e1f4456f4051d251ac63970b22ec6e3826d10 (diff)
downloadphp-git-dc467a70d302cd2554a647cacef7f4145b4910ba.tar.gz
- Fixed crash when zend_eval_string bailouts (-r 'a();')
Reported by: David Tajchreber
Diffstat (limited to 'sapi/cli/php_cli.c')
-rw-r--r--sapi/cli/php_cli.c811
1 files changed, 407 insertions, 404 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index ced9753377..cdce836445 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -668,495 +668,498 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */
const char *param_error=NULL;
int hide_argv = 0;
- CG(in_compilation) = 0; /* not initialized but needed for several options */
- EG(uninitialized_zval_ptr) = NULL;
+ zend_try {
+
+ CG(in_compilation) = 0; /* not initialized but needed for several options */
+ EG(uninitialized_zval_ptr) = NULL;
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
- switch (c) {
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
+ switch (c) {
- case 'i': /* php info & quit */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- goto err;
- }
- request_started = 1;
- php_print_info(0xFFFFFFFF TSRMLS_CC);
- php_output_end_all(TSRMLS_C);
- exit_status = (c == '?' && argc > 1 && !strchr(argv[1], c));
- goto out;
+ case 'i': /* php info & quit */
+ if (php_request_startup(TSRMLS_C)==FAILURE) {
+ goto err;
+ }
+ request_started = 1;
+ php_print_info(0xFFFFFFFF TSRMLS_CC);
+ php_output_end_all(TSRMLS_C);
+ exit_status = (c == '?' && argc > 1 && !strchr(argv[1], c));
+ goto out;
- case 'v': /* show php version & quit */
- php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2011 The PHP Group\n%s",
- PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,
+ case 'v': /* show php version & quit */
+ php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2011 The PHP Group\n%s",
+ PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__,
#if ZEND_DEBUG && defined(HAVE_GCOV)
- "(DEBUG GCOV)",
+ "(DEBUG GCOV)",
#elif ZEND_DEBUG
- "(DEBUG)",
+ "(DEBUG)",
#elif defined(HAVE_GCOV)
- "(GCOV)",
+ "(GCOV)",
#else
- "",
+ "",
#endif
- get_zend_version()
- );
- sapi_deactivate(TSRMLS_C);
- goto out;
+ get_zend_version()
+ );
+ sapi_deactivate(TSRMLS_C);
+ goto out;
- case 'm': /* list compiled in modules */
- if (php_request_startup(TSRMLS_C)==FAILURE) {
- goto err;
- }
- request_started = 1;
- php_printf("[PHP Modules]\n");
- print_modules(TSRMLS_C);
- php_printf("\n[Zend Modules]\n");
- print_extensions(TSRMLS_C);
- php_printf("\n");
- php_output_end_all(TSRMLS_C);
- exit_status=0;
- goto out;
+ case 'm': /* list compiled in modules */
+ if (php_request_startup(TSRMLS_C)==FAILURE) {
+ goto err;
+ }
+ request_started = 1;
+ php_printf("[PHP Modules]\n");
+ print_modules(TSRMLS_C);
+ php_printf("\n[Zend Modules]\n");
+ print_extensions(TSRMLS_C);
+ php_printf("\n");
+ php_output_end_all(TSRMLS_C);
+ exit_status=0;
+ goto out;
- default:
- break;
+ default:
+ break;
+ }
}
- }
- /* Set some CLI defaults */
- SG(options) |= SAPI_OPTION_NO_CHDIR;
+ /* Set some CLI defaults */
+ SG(options) |= SAPI_OPTION_NO_CHDIR;
- php_optind = orig_optind;
- php_optarg = orig_optarg;
- while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
- switch (c) {
+ php_optind = orig_optind;
+ php_optarg = orig_optarg;
+ while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
+ switch (c) {
- case 'a': /* interactive mode */
- if (!interactive) {
- if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
- break;
- }
+ case 'a': /* interactive mode */
+ if (!interactive) {
+ if (behavior != PHP_MODE_STANDARD) {
+ param_error = param_mode_conflict;
+ break;
+ }
- interactive=1;
- }
- break;
+ interactive=1;
+ }
+ break;
- case 'C': /* don't chdir to the script directory */
- /* This is default so NOP */
- break;
+ case 'C': /* don't chdir to the script directory */
+ /* This is default so NOP */
+ break;
- case 'F':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_run || script_file) {
- param_error = "You can use -R or -F only once.\n";
+ case 'F':
+ if (behavior == PHP_MODE_PROCESS_STDIN) {
+ if (exec_run || script_file) {
+ param_error = "You can use -R or -F only once.\n";
+ break;
+ }
+ } else if (behavior != PHP_MODE_STANDARD) {
+ param_error = param_mode_conflict;
break;
}
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
+ behavior=PHP_MODE_PROCESS_STDIN;
+ script_file = php_optarg;
break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- script_file = php_optarg;
- break;
- case 'f': /* parse file */
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = param_mode_conflict;
- break;
- } else if (script_file) {
- param_error = "You can use -f only once.\n";
+ case 'f': /* parse file */
+ if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
+ param_error = param_mode_conflict;
+ break;
+ } else if (script_file) {
+ param_error = "You can use -f only once.\n";
+ break;
+ }
+ script_file = php_optarg;
break;
- }
- script_file = php_optarg;
- break;
- case 'l': /* syntax check mode */
- if (behavior != PHP_MODE_STANDARD) {
+ case 'l': /* syntax check mode */
+ if (behavior != PHP_MODE_STANDARD) {
+ break;
+ }
+ behavior=PHP_MODE_LINT;
break;
- }
- behavior=PHP_MODE_LINT;
- break;
#if 0 /* not yet operational, see also below ... */
- case '': /* generate indented source mode*/
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = "Source indenting only works for files.\n";
+ case '': /* generate indented source mode*/
+ if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
+ param_error = "Source indenting only works for files.\n";
+ break;
+ }
+ behavior=PHP_MODE_INDENT;
break;
- }
- behavior=PHP_MODE_INDENT;
- break;
#endif
- case 'q': /* do not generate HTTP headers */
- /* This is default so NOP */
- break;
+ case 'q': /* do not generate HTTP headers */
+ /* This is default so NOP */
+ break;
- case 'r': /* run code from command line */
- if (behavior == PHP_MODE_CLI_DIRECT) {
- if (exec_direct || script_file) {
- param_error = "You can use -r only once.\n";
+ case 'r': /* run code from command line */
+ if (behavior == PHP_MODE_CLI_DIRECT) {
+ if (exec_direct || script_file) {
+ param_error = "You can use -r only once.\n";
+ break;
+ }
+ } else if (behavior != PHP_MODE_STANDARD || interactive) {
+ param_error = param_mode_conflict;
break;
}
- } else if (behavior != PHP_MODE_STANDARD || interactive) {
- param_error = param_mode_conflict;
+ behavior=PHP_MODE_CLI_DIRECT;
+ exec_direct=php_optarg;
break;
- }
- behavior=PHP_MODE_CLI_DIRECT;
- exec_direct=php_optarg;
- break;
-
- case 'R':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_run || script_file) {
- param_error = "You can use -R or -F only once.\n";
+
+ case 'R':
+ if (behavior == PHP_MODE_PROCESS_STDIN) {
+ if (exec_run || script_file) {
+ param_error = "You can use -R or -F only once.\n";
+ break;
+ }
+ } else if (behavior != PHP_MODE_STANDARD) {
+ param_error = param_mode_conflict;
break;
}
- } else if (behavior != PHP_MODE_STANDARD) {
- param_error = param_mode_conflict;
+ behavior=PHP_MODE_PROCESS_STDIN;
+ exec_run=php_optarg;
break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- exec_run=php_optarg;
- break;
- case 'B':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_begin) {
- param_error = "You can use -B only once.\n";
+ case 'B':
+ if (behavior == PHP_MODE_PROCESS_STDIN) {
+ if (exec_begin) {
+ param_error = "You can use -B only once.\n";
+ break;
+ }
+ } else if (behavior != PHP_MODE_STANDARD || interactive) {
+ param_error = param_mode_conflict;
break;
}
- } else if (behavior != PHP_MODE_STANDARD || interactive) {
- param_error = param_mode_conflict;
+ behavior=PHP_MODE_PROCESS_STDIN;
+ exec_begin=php_optarg;
break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- exec_begin=php_optarg;
- break;
- case 'E':
- if (behavior == PHP_MODE_PROCESS_STDIN) {
- if (exec_end) {
- param_error = "You can use -E only once.\n";
+ case 'E':
+ if (behavior == PHP_MODE_PROCESS_STDIN) {
+ if (exec_end) {
+ param_error = "You can use -E only once.\n";
+ break;
+ }
+ } else if (behavior != PHP_MODE_STANDARD || interactive) {
+ param_error = param_mode_conflict;
break;
}
- } else if (behavior != PHP_MODE_STANDARD || interactive) {
- param_error = param_mode_conflict;
+ behavior=PHP_MODE_PROCESS_STDIN;
+ exec_end=php_optarg;
break;
- }
- behavior=PHP_MODE_PROCESS_STDIN;
- exec_end=php_optarg;
- break;
- case 's': /* generate highlighted HTML from source */
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = "Source highlighting only works for files.\n";
+ case 's': /* generate highlighted HTML from source */
+ if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
+ param_error = "Source highlighting only works for files.\n";
+ break;
+ }
+ behavior=PHP_MODE_HIGHLIGHT;
break;
- }
- behavior=PHP_MODE_HIGHLIGHT;
- break;
- case 'w':
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
- param_error = "Source stripping only works for files.\n";
+ case 'w':
+ if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) {
+ param_error = "Source stripping only works for files.\n";
+ break;
+ }
+ behavior=PHP_MODE_STRIP;
break;
- }
- behavior=PHP_MODE_STRIP;
- break;
- case 'z': /* load extension file */
- zend_load_extension(php_optarg);
- break;
- case 'H':
- hide_argv = 1;
- break;
- case 10:
- behavior=PHP_MODE_REFLECTION_FUNCTION;
- reflection_what = php_optarg;
- break;
- case 11:
- behavior=PHP_MODE_REFLECTION_CLASS;
- reflection_what = php_optarg;
- break;
- case 12:
- behavior=PHP_MODE_REFLECTION_EXTENSION;
- reflection_what = php_optarg;
- break;
- case 13:
- behavior=PHP_MODE_REFLECTION_ZEND_EXTENSION;
- reflection_what = php_optarg;
- break;
- case 14:
- behavior=PHP_MODE_REFLECTION_EXT_INFO;
- reflection_what = php_optarg;
- break;
- case 15:
- behavior = PHP_MODE_SHOW_INI_CONFIG;
- break;
- default:
- break;
+ case 'z': /* load extension file */
+ zend_load_extension(php_optarg);
+ break;
+ case 'H':
+ hide_argv = 1;
+ break;
+ case 10:
+ behavior=PHP_MODE_REFLECTION_FUNCTION;
+ reflection_what = php_optarg;
+ break;
+ case 11:
+ behavior=PHP_MODE_REFLECTION_CLASS;
+ reflection_what = php_optarg;
+ break;
+ case 12:
+ behavior=PHP_MODE_REFLECTION_EXTENSION;
+ reflection_what = php_optarg;
+ break;
+ case 13:
+ behavior=PHP_MODE_REFLECTION_ZEND_EXTENSION;
+ reflection_what = php_optarg;
+ break;
+ case 14:
+ behavior=PHP_MODE_REFLECTION_EXT_INFO;
+ reflection_what = php_optarg;
+ break;
+ case 15:
+ behavior = PHP_MODE_SHOW_INI_CONFIG;
+ break;
+ default:
+ break;
+ }
}
- }
- if (param_error) {
- PUTS(param_error);
- exit_status=1;
- goto err;
- }
+ if (param_error) {
+ PUTS(param_error);
+ exit_status=1;
+ goto err;
+ }
- if (interactive) {
+ if (interactive) {
#if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE)
- printf("Interactive shell\n\n");
+ printf("Interactive shell\n\n");
#else
- printf("Interactive mode enabled\n\n");
+ printf("Interactive mode enabled\n\n");
#endif
- fflush(stdout);
- }
-
- 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 > php_optind
- && !script_file
- && behavior!=PHP_MODE_CLI_DIRECT
- && behavior!=PHP_MODE_PROCESS_STDIN
- && strcmp(argv[php_optind-1],"--"))
- {
- script_file=argv[php_optind];
- php_optind++;
- }
- if (script_file) {
- if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
- goto err;
+ fflush(stdout);
}
- script_filename = script_file;
- } else {
- /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */
- /* here but this would make things only more complicated. And it */
- /* is consitent with the way -R works where the stdin file handle*/
- /* is also accessible. */
- file_handle.filename = "-";
- file_handle.handle.fp = stdin;
- }
- file_handle.type = ZEND_HANDLE_FP;
- file_handle.opened_path = NULL;
- file_handle.free_filename = 0;
- php_self = file_handle.filename;
-
- /* before registering argv to module exchange the *new* argv[0] */
- /* we can achieve this without allocating more memory */
- 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[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;
- fclose(file_handle.handle.fp);
- PUTS("Could not startup.\n");
- goto err;
- }
- request_started = 1;
- CG(start_lineno) = lineno;
- *arg_excp = arg_free; /* reconstuct argv */
-
- if (hide_argv) {
- int i;
- for (i = 1; i < argc; i++) {
- memset(argv[i], 0, strlen(argv[i]));
- }
- }
- zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
+ CG(interactive) = interactive;
- PG(during_request_startup) = 0;
- switch (behavior) {
- case PHP_MODE_STANDARD:
- if (strcmp(file_handle.filename, "-")) {
- cli_register_file_handles(TSRMLS_C);
+ /* only set script_file if not set already and not in direct mode and not at end of parameter list */
+ if (argc > php_optind
+ && !script_file
+ && behavior!=PHP_MODE_CLI_DIRECT
+ && behavior!=PHP_MODE_PROCESS_STDIN
+ && strcmp(argv[php_optind-1],"--"))
+ {
+ script_file=argv[php_optind];
+ php_optind++;
}
-
- if (interactive && cli_shell_callbacks.cli_shell_run) {
- exit_status = cli_shell_callbacks.cli_shell_run(TSRMLS_C);
+ if (script_file) {
+ if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
+ goto err;
+ }
+ script_filename = script_file;
} else {
- php_execute_script(&file_handle TSRMLS_CC);
- exit_status = EG(exit_status);
+ /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */
+ /* here but this would make things only more complicated. And it */
+ /* is consitent with the way -R works where the stdin file handle*/
+ /* is also accessible. */
+ file_handle.filename = "-";
+ file_handle.handle.fp = stdin;
}
- break;
- case PHP_MODE_LINT:
- exit_status = php_lint_script(&file_handle TSRMLS_CC);
- if (exit_status==SUCCESS) {
- zend_printf("No syntax errors detected in %s\n", file_handle.filename);
- } else {
- zend_printf("Errors parsing %s\n", file_handle.filename);
+ file_handle.type = ZEND_HANDLE_FP;
+ file_handle.opened_path = NULL;
+ file_handle.free_filename = 0;
+ php_self = file_handle.filename;
+
+ /* before registering argv to module exchange the *new* argv[0] */
+ /* we can achieve this without allocating more memory */
+ 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[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;
+ fclose(file_handle.handle.fp);
+ PUTS("Could not startup.\n");
+ goto err;
}
- break;
- case PHP_MODE_STRIP:
- if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- zend_strip(TSRMLS_C);
+ request_started = 1;
+ CG(start_lineno) = lineno;
+ *arg_excp = arg_free; /* reconstuct argv */
+
+ if (hide_argv) {
+ int i;
+ for (i = 1; i < argc; i++) {
+ memset(argv[i], 0, strlen(argv[i]));
+ }
}
- goto out;
- break;
- case PHP_MODE_HIGHLIGHT:
- {
- zend_syntax_highlighter_ini syntax_highlighter_ini;
+ zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
+
+ PG(during_request_startup) = 0;
+ switch (behavior) {
+ case PHP_MODE_STANDARD:
+ if (strcmp(file_handle.filename, "-")) {
+ cli_register_file_handles(TSRMLS_C);
+ }
+
+ if (interactive && cli_shell_callbacks.cli_shell_run) {
+ exit_status = cli_shell_callbacks.cli_shell_run(TSRMLS_C);
+ } else {
+ php_execute_script(&file_handle TSRMLS_CC);
+ exit_status = EG(exit_status);
+ }
+ break;
+ case PHP_MODE_LINT:
+ exit_status = php_lint_script(&file_handle TSRMLS_CC);
+ if (exit_status==SUCCESS) {
+ zend_printf("No syntax errors detected in %s\n", file_handle.filename);
+ } else {
+ zend_printf("Errors parsing %s\n", file_handle.filename);
+ }
+ break;
+ case PHP_MODE_STRIP:
if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
- php_get_highlight_struct(&syntax_highlighter_ini);
- zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
+ zend_strip(TSRMLS_C);
}
goto out;
- }
- break;
-#if 0
- /* Zeev might want to do something with this one day */
- case PHP_MODE_INDENT:
- open_file_for_scanning(&file_handle TSRMLS_CC);
- zend_indent();
- zend_file_handle_dtor(file_handle.handle TSRMLS_CC);
- goto out;
- break;
-#endif
- case PHP_MODE_CLI_DIRECT:
- cli_register_file_handles(TSRMLS_C);
- if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1 TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- break;
-
- case PHP_MODE_PROCESS_STDIN:
- {
- char *input;
- size_t len, index = 0;
- zval *argn, *argi;
-
- cli_register_file_handles(TSRMLS_C);
+ break;
+ case PHP_MODE_HIGHLIGHT:
+ {
+ zend_syntax_highlighter_ini syntax_highlighter_ini;
- if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1 TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- ALLOC_ZVAL(argi);
- Z_TYPE_P(argi) = IS_LONG;
- Z_LVAL_P(argi) = index;
- INIT_PZVAL(argi);
- zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(zval *), NULL);
- while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) {
- len = strlen(input);
- while (len-- && (input[len]=='\n' || input[len]=='\r')) {
- input[len] = '\0';
+ if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) {
+ php_get_highlight_struct(&syntax_highlighter_ini);
+ zend_highlight(&syntax_highlighter_ini TSRMLS_CC);
}
- ALLOC_ZVAL(argn);
- Z_TYPE_P(argn) = IS_STRING;
- Z_STRLEN_P(argn) = ++len;
- Z_STRVAL_P(argn) = estrndup(input, len);
- INIT_PZVAL(argn);
- zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(zval *), NULL);
- Z_LVAL_P(argi) = ++index;
- if (exec_run) {
- if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) == FAILURE) {
- exit_status=254;
- }
- } else {
- if (script_file) {
- if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
- exit_status = 1;
- } else {
- CG(start_lineno) = lineno;
- php_execute_script(&file_handle TSRMLS_CC);
- exit_status = EG(exit_status);
- }
- }
- }
- efree(input);
+ goto out;
}
- if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1 TSRMLS_CC) == FAILURE) {
+ break;
+#if 0
+ /* Zeev might want to do something with this one day */
+ case PHP_MODE_INDENT:
+ open_file_for_scanning(&file_handle TSRMLS_CC);
+ zend_indent();
+ zend_file_handle_dtor(file_handle.handle TSRMLS_CC);
+ goto out;
+ break;
+#endif
+ case PHP_MODE_CLI_DIRECT:
+ cli_register_file_handles(TSRMLS_C);
+ if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1 TSRMLS_CC) == FAILURE) {
exit_status=254;
}
-
break;
- }
- case PHP_MODE_REFLECTION_FUNCTION:
- case PHP_MODE_REFLECTION_CLASS:
- case PHP_MODE_REFLECTION_EXTENSION:
- case PHP_MODE_REFLECTION_ZEND_EXTENSION:
+
+ case PHP_MODE_PROCESS_STDIN:
{
- zend_class_entry *pce = NULL;
- zval *arg, *ref;
- zend_execute_data execute_data;
+ char *input;
+ size_t len, index = 0;
+ zval *argn, *argi;
- switch (behavior) {
- default:
- break;
- case PHP_MODE_REFLECTION_FUNCTION:
- if (strstr(reflection_what, "::")) {
- pce = reflection_method_ptr;
- } else {
- pce = reflection_function_ptr;
+ cli_register_file_handles(TSRMLS_C);
+
+ if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1 TSRMLS_CC) == FAILURE) {
+ exit_status=254;
+ }
+ ALLOC_ZVAL(argi);
+ Z_TYPE_P(argi) = IS_LONG;
+ Z_LVAL_P(argi) = index;
+ INIT_PZVAL(argi);
+ zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(zval *), NULL);
+ while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) {
+ len = strlen(input);
+ while (len-- && (input[len]=='\n' || input[len]=='\r')) {
+ input[len] = '\0';
+ }
+ ALLOC_ZVAL(argn);
+ Z_TYPE_P(argn) = IS_STRING;
+ Z_STRLEN_P(argn) = ++len;
+ Z_STRVAL_P(argn) = estrndup(input, len);
+ INIT_PZVAL(argn);
+ zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(zval *), NULL);
+ Z_LVAL_P(argi) = ++index;
+ if (exec_run) {
+ if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) == FAILURE) {
+ exit_status=254;
}
- break;
- case PHP_MODE_REFLECTION_CLASS:
- pce = reflection_class_ptr;
- break;
- case PHP_MODE_REFLECTION_EXTENSION:
- pce = reflection_extension_ptr;
- break;
- case PHP_MODE_REFLECTION_ZEND_EXTENSION:
- pce = reflection_zend_extension_ptr;
- break;
+ } else {
+ if (script_file) {
+ if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) {
+ exit_status = 1;
+ } else {
+ CG(start_lineno) = lineno;
+ php_execute_script(&file_handle TSRMLS_CC);
+ exit_status = EG(exit_status);
+ }
+ }
+ }
+ efree(input);
}
-
- MAKE_STD_ZVAL(arg);
- ZVAL_STRING(arg, reflection_what, 1);
- ALLOC_ZVAL(ref);
- object_init_ex(ref, pce);
- INIT_PZVAL(ref);
-
- memset(&execute_data, 0, sizeof(zend_execute_data));
- EG(current_execute_data) = &execute_data;
- EX(function_state).function = pce->constructor;
- zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, arg);
-
- if (EG(exception)) {
- zval *msg = zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception), "message", sizeof("message")-1, 0 TSRMLS_CC);
- zend_printf("Exception: %s\n", Z_STRVAL_P(msg));
- zval_ptr_dtor(&EG(exception));
- EG(exception) = NULL;
- } else {
- zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, ref);
+ if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1 TSRMLS_CC) == FAILURE) {
+ exit_status=254;
}
- zval_ptr_dtor(&ref);
- zval_ptr_dtor(&arg);
break;
}
- case PHP_MODE_REFLECTION_EXT_INFO:
- {
- int len = strlen(reflection_what);
- char *lcname = zend_str_tolower_dup(reflection_what, len);
- zend_module_entry *module;
+ case PHP_MODE_REFLECTION_FUNCTION:
+ case PHP_MODE_REFLECTION_CLASS:
+ case PHP_MODE_REFLECTION_EXTENSION:
+ case PHP_MODE_REFLECTION_ZEND_EXTENSION:
+ {
+ zend_class_entry *pce = NULL;
+ zval *arg, *ref;
+ zend_execute_data execute_data;
+
+ switch (behavior) {
+ default:
+ break;
+ case PHP_MODE_REFLECTION_FUNCTION:
+ if (strstr(reflection_what, "::")) {
+ pce = reflection_method_ptr;
+ } else {
+ pce = reflection_function_ptr;
+ }
+ break;
+ case PHP_MODE_REFLECTION_CLASS:
+ pce = reflection_class_ptr;
+ break;
+ case PHP_MODE_REFLECTION_EXTENSION:
+ pce = reflection_extension_ptr;
+ break;
+ case PHP_MODE_REFLECTION_ZEND_EXTENSION:
+ pce = reflection_zend_extension_ptr;
+ break;
+ }
+
+ MAKE_STD_ZVAL(arg);
+ ZVAL_STRING(arg, reflection_what, 1);
+ ALLOC_ZVAL(ref);
+ object_init_ex(ref, pce);
+ INIT_PZVAL(ref);
+
+ memset(&execute_data, 0, sizeof(zend_execute_data));
+ EG(current_execute_data) = &execute_data;
+ EX(function_state).function = pce->constructor;
+ zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, arg);
+
+ if (EG(exception)) {
+ zval *msg = zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception), "message", sizeof("message")-1, 0 TSRMLS_CC);
+ zend_printf("Exception: %s\n", Z_STRVAL_P(msg));
+ zval_ptr_dtor(&EG(exception));
+ EG(exception) = NULL;
+ } else {
+ zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, ref);
+ }
+ zval_ptr_dtor(&ref);
+ zval_ptr_dtor(&arg);
- if (zend_hash_find(&module_registry, lcname, len+1, (void**)&module) == FAILURE) {
- if (!strcmp(reflection_what, "main")) {
- display_ini_entries(NULL);
+ break;
+ }
+ case PHP_MODE_REFLECTION_EXT_INFO:
+ {
+ int len = strlen(reflection_what);
+ char *lcname = zend_str_tolower_dup(reflection_what, len);
+ zend_module_entry *module;
+
+ if (zend_hash_find(&module_registry, lcname, len+1, (void**)&module) == FAILURE) {
+ if (!strcmp(reflection_what, "main")) {
+ display_ini_entries(NULL);
+ } else {
+ zend_printf("Extension '%s' not present.\n", reflection_what);
+ exit_status = 1;
+ }
} else {
- zend_printf("Extension '%s' not present.\n", reflection_what);
- exit_status = 1;
+ php_info_print_module(module TSRMLS_CC);
}
- } else {
- php_info_print_module(module TSRMLS_CC);
+
+ efree(lcname);
+ break;
}
-
- efree(lcname);
- break;
- }
- case PHP_MODE_SHOW_INI_CONFIG:
- {
- zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
- zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
- zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
- zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
- break;
- }
- }
+ case PHP_MODE_SHOW_INI_CONFIG:
+ {
+ zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH);
+ zend_printf("Loaded Configuration File: %s\n", php_ini_opened_path ? php_ini_opened_path : "(none)");
+ zend_printf("Scan for additional .ini files in: %s\n", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
+ zend_printf("Additional .ini files parsed: %s\n", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
+ break;
+ }
+ }
+ } zend_end_try();
out:
if (exit_status == 0) {