com php-src: fix crash when cleaning environment fix crash when specifying exec on command line: phpdbg.c phpdbg.h phpdbg_prompt.c p hpdbg_prompt.h
| From: | Bob Weinand | Date: | Thu, 14 Nov 2013 11:13:21 +0000 |
| Subject: | com php-src: fix crash when cleaning environment fix crash when specifying exec on command line: phpdbg.c phpdbg.h phpdbg_prompt.c p hpdbg_prompt.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74984@lists.php.net to get a copy of this message | ||
Commit: dcb6906bc4df5a3f7f86f1e72c107671a7bc32c1
Author: krakjoe <joe.watkins@live.co.uk> Thu, 14 Nov 2013 11:13:21 +0000
Parents: 6eba5c66644d9b1c39aefee27ff1176f7a4f8742
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dcb6906bc4df5a3f7f86f1e72c107671a7bc32c1
Log:
fix crash when cleaning environment
fix crash when specifying exec on command line
Changed paths:
M phpdbg.c
M phpdbg.h
M phpdbg_prompt.c
M phpdbg_prompt.h
Diff:
diff --git a/phpdbg.c b/phpdbg.c
index 961526c..841eeda 100644
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -101,12 +101,15 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
if (PHPDBG_G(exec)) {
efree(PHPDBG_G(exec));
+ PHPDBG_G(exec) = NULL;
}
if (PHPDBG_G(ops)) {
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
efree(PHPDBG_G(ops));
+ PHPDBG_G(ops) = NULL;
}
+
return SUCCESS;
} /* }}} */
@@ -318,18 +321,21 @@ void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */
INI_DEFAULT("display_errors", "1");
} /* }}} */
+static jmp_buf phpdbg_main;
+
int main(int argc, char **argv) /* {{{ */
{
sapi_module_struct *phpdbg = &phpdbg_sapi_module;
- char *ini_entries = NULL;
- int ini_entries_len = 0;
- char *exec = NULL;
- size_t exec_len = 0L;
- zend_ulong flags = PHPDBG_DEFAULT_FLAGS;
- char *php_optarg = NULL;
- int php_optind = 1;
+ char *ini_entries;
+ int ini_entries_len;
+ char *exec;
+ size_t exec_len;
+ zend_ulong flags;
+ char *php_optarg;
+ int php_optind;
int opt;
-
+ long cleaning = 0;
+
#ifdef ZTS
void ***tsrm_ls;
#endif
@@ -347,6 +353,16 @@ int main(int argc, char **argv) /* {{{ */
tsrm_ls = ts_resource(0);
#endif
+phpdbg_main:
+ ini_entries = NULL;
+ ini_entries_len = 0;
+ exec = NULL;
+ exec_len = 0;
+ flags = PHPDBG_DEFAULT_FLAGS;
+ php_optarg = NULL;
+ php_optind = 1;
+ opt = 0;
+
while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (opt) {
case 'n':
@@ -394,7 +410,7 @@ int main(int argc, char **argv) /* {{{ */
case 'e': /* set execution context */
exec_len = strlen(php_optarg);
if (exec_len) {
- exec = phpdbg_resolve_path(php_optarg TSRMLS_CC);
+ exec = strdup(php_optarg);
}
break;
@@ -446,8 +462,9 @@ int main(int argc, char **argv) /* {{{ */
PG(modules_activated) = 0;
if (exec) { /* set execution context */
- PHPDBG_G(exec) = exec;
- PHPDBG_G(exec_len) = exec_len;
+ PHPDBG_G(exec) = phpdbg_resolve_path(
+ exec TSRMLS_CC);
+ PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
free(exec);
}
@@ -463,18 +480,18 @@ int main(int argc, char **argv) /* {{{ */
zend_activate_auto_globals(TSRMLS_C);
} zend_end_try();
- /* print blurb */
- phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s",
- PHPDBG_VERSION);
- phpdbg_writeln("To get help using phpdbg type \"help\" and press
enter");
- phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES);
-
+ /* print blurb */
+ phpdbg_welcome(cleaning TSRMLS_CC);
+ /* phpdbg main() */
do {
zend_try {
phpdbg_interactive(TSRMLS_C);
} zend_catch {
-
+ if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) {
+ cleaning = 1;
+ break;
+ } else cleaning = 0;
} zend_end_try();
} while(!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
@@ -504,9 +521,14 @@ int main(int argc, char **argv) /* {{{ */
sapi_shutdown();
}
+
+ if (cleaning) {
+ goto phpdbg_main;
+ }
#ifdef ZTS
- tsrm_shutdown();
+ /* bugggy */
+ //tsrm_shutdown();
#endif
return 0;
diff --git a/phpdbg.h b/phpdbg.h
index 15155e1..ccec0b4 100644
--- a/phpdbg.h
+++ b/phpdbg.h
@@ -83,6 +83,7 @@
#define PHPDBG_IS_QUIET 0x000100000000
#define PHPDBG_IS_QUITTING 0x001000000000
#define PHPDBG_IS_COLOURED 0x010000000000
+#define PHPDBG_IS_CLEANING 0x100000000000
#ifndef _WIN32
# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED)
diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c
index 4500cb8..91e9990 100644
--- a/phpdbg_prompt.c
+++ b/phpdbg_prompt.c
@@ -71,6 +71,24 @@ static const phpdbg_command_t phpdbg_prompt_commands[] = {
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */
+{
+ /* print blurb */
+ if (!cleaning) {
+ phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s",
+ PHPDBG_VERSION);
+ phpdbg_writeln("To get help using phpdbg type \"help\" and press
enter");
+ phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES);
+ } else {
+ phpdbg_notice("Clean Execution Environment");
+
+ phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table)));
+ phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table)));
+ phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants)));
+ phpdbg_writeln("Includes\t\t%d",
zend_hash_num_elements(&EG(included_files)));
+ }
+} /* }}} */
+
static PHPDBG_COMMAND(exec) /* {{{ */
{
if (expr_len == 0) {
@@ -362,28 +380,16 @@ static PHPDBG_COMMAND(break) /* {{{ */
static PHPDBG_COMMAND(quit) /* {{{ */
{
- PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
-
- zend_bailout();
+ /* don't allow this to loop, ever ... */
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+
+ PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+ zend_bailout();
+ }
return SUCCESS;
} /* }}} */
-static int clean_non_persistent_constant_full(const zend_constant *c TSRMLS_DC) /* {{{ */
-{
- return (c->flags & CONST_PERSISTENT) ? 0 : 1;
-} /* }}} */
-
-static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC) /* {{{ */
-{
- return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_REMOVE;
-} /* }}} */
-
-static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC) /* {{{ */
-{
- return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_KEEP :
ZEND_HASH_APPLY_REMOVE;
-} /* }}} */
-
static PHPDBG_COMMAND(clean) /* {{{ */
{
if (EG(in_execution)) {
@@ -400,13 +406,6 @@ static PHPDBG_COMMAND(clean) /* {{{ */
phpdbg_clean(1 TSRMLS_CC);
- phpdbg_notice("Clean Execution Environment");
-
- phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files)));
-
return SUCCESS;
} /* }}} */
@@ -661,8 +660,6 @@ void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags
void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
{
- zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC);
-
/* this is implicitly required */
if (PHPDBG_G(ops)) {
destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
@@ -670,14 +667,11 @@ void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
PHPDBG_G(ops) = NULL;
}
- if (full) {
- zend_hash_reverse_apply(EG(function_table),
- (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
- zend_hash_reverse_apply(EG(class_table),
- (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
- zend_hash_reverse_apply(EG(zend_constants),
- (apply_func_t) clean_non_persistent_constant_full TSRMLS_CC);
- zend_hash_clean(&EG(included_files));
+ if (full)
+ {
+ PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
+
+ zend_bailout();
}
} /* }}} */
diff --git a/phpdbg_prompt.h b/phpdbg_prompt.h
index 2739ac7..b7d7101 100644
--- a/phpdbg_prompt.h
+++ b/phpdbg_prompt.h
@@ -61,6 +61,7 @@ int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_le
#define PHPDBG_COMMAND(name) \
int phpdbg_do_##name(const char *expr, size_t expr_len TSRMLS_DC)
+void phpdbg_welcome(zend_bool cleaning TSRMLS_DC);
int phpdbg_interactive(TSRMLS_D);
void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC);
void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC);