]> granicus.if.org Git - php/commitdiff
Fix misbehaviors with uncaught exceptions and finally or eval
authorBob Weinand <bobwei9@hotmail.com>
Mon, 20 Jul 2015 15:52:57 +0000 (17:52 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Mon, 20 Jul 2015 16:00:43 +0000 (18:00 +0200)
sapi/phpdbg/phpdbg_prompt.c
sapi/phpdbg/phpdbg_utils.c

index a553255b4af1e5df9c71f901d0fa6794fd6aec39..b00952c07b357a95df54faa28526cdf49fdc112c 100644 (file)
@@ -659,6 +659,7 @@ PHPDBG_COMMAND(run) /* {{{ */
                        char **argv = emalloc(5 * sizeof(char *));
                        int argc = 0;
                        int i;
+                       /* TODO allow proper escaping with \,  "" and '' here */
                        char *argv_str = strtok(param->str, " ");
 
                        while (argv_str) {
@@ -767,15 +768,19 @@ PHPDBG_COMMAND(ev) /* {{{ */
        PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
        zend_try {
                if (zend_eval_stringl(param->str, param->len, &retval, "eval()'d code") == SUCCESS) {
-                       phpdbg_xml("<eval %r>");
-                       if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
-                               zval *zvp = &retval;
-                               phpdbg_xml_var_dump(zvp);
+                       if (EG(exception)) {
+                               zend_exception_error(EG(exception), E_ERROR);
+                       } else {
+                               phpdbg_xml("<eval %r>");
+                               if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+                                       zval *zvp = &retval;
+                                       phpdbg_xml_var_dump(zvp);
+                               }
+                               zend_print_zval_r(&retval, 0);
+                               phpdbg_xml("</eval>");
+                               phpdbg_out("\n");
+                               zval_ptr_dtor(&retval);
                        }
-                       zend_print_zval_r(&retval, 0);
-                       phpdbg_xml("</eval>");
-                       phpdbg_out("\n");
-                       zval_ptr_dtor(&retval);
                }
        } zend_catch {
                EG(current_execute_data) = original_execute_data;
@@ -784,6 +789,7 @@ PHPDBG_COMMAND(ev) /* {{{ */
                EG(vm_stack_end) = original_stack->end;
                EG(vm_stack) = original_stack;
        } zend_end_try();
+
        PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
 
        /* switch stepping back on */
@@ -1391,18 +1397,17 @@ void phpdbg_clean(zend_bool full) /* {{{ */
        \
        switch (phpdbg_interactive(allow_async_unsafe)) { \
                zval zv; \
-               default: \
+               case PHPDBG_LEAVE: \
+               case PHPDBG_FINISH: \
+               case PHPDBG_UNTIL: \
+               case PHPDBG_NEXT: \
                        if (exception) { \
                                Z_OBJ(zv) = exception; \
                                zend_throw_exception_internal(&zv); \
                        } \
                        /* fallthrough */ \
-               case PHPDBG_LEAVE: \
-               case PHPDBG_FINISH: \
-               case PHPDBG_UNTIL: \
-               case PHPDBG_NEXT:{ \
+               default: \
                        goto next; \
-               } \
        } \
 } while (0)
 
@@ -1431,7 +1436,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
 #endif
 
                /* check for uncaught exceptions */
-               if (exception && PHPDBG_G(handled_exception) != exception) {
+               if (exception && PHPDBG_G(handled_exception) != exception && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
                        zend_execute_data *prev_ex = execute_data;
                        zval zv, rv;
                        zend_string *file, *msg;
@@ -1464,16 +1469,14 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
                }
 ex_is_caught:
 
-               /* allow conditional breakpoints and
-                       initialization to access the vm uninterrupted */
-               if ((PHPDBG_G(flags) & PHPDBG_IN_COND_BP) ||
-                       (PHPDBG_G(flags) & PHPDBG_IS_INITIALIZING)) {
+               /* allow conditional breakpoints and initialization to access the vm uninterrupted */
+               if (PHPDBG_G(flags) & (PHPDBG_IN_COND_BP | PHPDBG_IS_INITIALIZING)) {
                        /* skip possible breakpoints */
                        goto next;
                }
 
                /* perform seek operation */
-               if (PHPDBG_G(flags) & PHPDBG_SEEK_MASK) {
+               if ((PHPDBG_G(flags) & PHPDBG_SEEK_MASK) && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
                        /* current address */
                        zend_ulong address = (zend_ulong) execute_data->opline;
 
index fc34c094b63bd4637adfc490b0761d727393fe85..2e1e1ed70c49581f21c246d6672e77e2d6854172 100644 (file)
@@ -728,11 +728,11 @@ PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *execute_data, zen
 
        op_num = op - op_array->opcodes;
 
-       for (i = 0; i < op_array->last_try_catch && op_array->try_catch_array[i].try_op < op_num; i++) {
+       for (i = 0; i < op_array->last_try_catch && op_array->try_catch_array[i].try_op <= op_num; i++) {
                uint32_t catch = op_array->try_catch_array[i].catch_op, finally = op_array->try_catch_array[i].finally_op;
                if (op_num <= catch || op_num <= finally) {
-                       if (finally && finally < catch) {
-                               return 0;
+                       if (finally) {
+                               return 1;
                        }
 
                        do {