]> granicus.if.org Git - php/commitdiff
Also consider specific catches when checking for uncaught
authorBob Weinand <bobwei9@hotmail.com>
Tue, 21 Apr 2015 23:07:52 +0000 (01:07 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Tue, 21 Apr 2015 23:08:08 +0000 (01:08 +0200)
sapi/phpdbg/phpdbg_prompt.c
sapi/phpdbg/phpdbg_utils.c
sapi/phpdbg/phpdbg_utils.h

index 11af5bc79002a8fd6ba4dca9a5c0b2326c7ca228..e2978fb5c729eecce90580755cf5b98e73fc94c9 100644 (file)
@@ -1446,12 +1446,12 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
                                        continue;
                                }
 
-                               if (phpdbg_check_caught_ex(prev_ex)) {
+                               if (phpdbg_check_caught_ex(prev_ex, exception)) {
                                        goto ex_is_caught;
                                }
                        } while ((prev_ex = prev_ex->prev_execute_data));
 
-                       PHPDBG_G(handled_exception) = EG(exception);
+                       PHPDBG_G(handled_exception) = exception;
                        phpdbg_error("exception", "name=\"%s\"", "Uncaught exception %s", exception->ce->name->val);
                        DO_INTERACTIVE(1);
                }
@@ -1474,7 +1474,7 @@ ex_is_caught:
                                goto next;
                        }
 
-#define INDEX_EXISTS_CHECK (zend_hash_index_exists(&PHPDBG_G(seek), address) || (EG(exception) && phpdbg_check_caught_ex(execute_data) == 0))
+#define INDEX_EXISTS_CHECK (zend_hash_index_exists(&PHPDBG_G(seek), address) || (exception && phpdbg_check_caught_ex(execute_data, exception) == 0))
 
                        /* run to next line */
                        if (PHPDBG_G(flags) & PHPDBG_IN_UNTIL) {
index fce042a2254a6fa9dd84d864be35155598e9f3cd..9d63fcf727fd93b5a95e28d6f1a349e5a8a1ba51 100644 (file)
@@ -713,24 +713,46 @@ head_done:
        } phpdbg_end_try_access();
 }
 
-PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex) {
+PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *execute_data, zend_object *exception) {
        const zend_op *op;
+       zend_op *cur;
        uint32_t op_num, i;
-       zend_op_array *op_array = &ex->func->op_array;
+       zend_op_array *op_array = &execute_data->func->op_array;
 
-       if (ex->opline >= EG(exception_op) && ex->opline < EG(exception_op) + 3) {
+       if (execute_data->opline >= EG(exception_op) && execute_data->opline < EG(exception_op) + 3) {
                op = EG(opline_before_exception);
        } else {
-               op = ex->opline;
+               op = execute_data->opline;
        }
 
        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++) {
-               if (op_num <= op_array->try_catch_array[i].catch_op || op_num <= op_array->try_catch_array[i].finally_op) {
-                       return 1;
+               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;
+                       }
+
+                       do {
+                               zend_class_entry *ce;
+                               cur = &op_array->opcodes[catch];
+
+                               if (!(ce = CACHED_PTR(Z_CACHE_SLOT_P(EX_CONSTANT(cur->op1))))) {
+                                       ce = zend_fetch_class_by_name(Z_STR_P(EX_CONSTANT(cur->op1)), EX_CONSTANT(cur->op1) + 1, ZEND_FETCH_CLASS_NO_AUTOLOAD);
+                                       CACHE_PTR(Z_CACHE_SLOT_P(EX_CONSTANT(cur->op1)), ce);
+                               }
+
+                               if (ce == exception->ce || (ce && instanceof_function(exception->ce, ce))) {
+                                       return 1;
+                               }
+
+                               catch = cur->extended_value;
+                       } while (!cur->result.num);
+
+                       return 0;
                }
        }
 
-       return 0;
+       return op->opcode == ZEND_CATCH;
 }
index 5ed235398793542cde57452c7ae2f6980f194dab..dcf713e05ba85fa3244be28761991e06a704919e 100644 (file)
@@ -94,7 +94,7 @@ int phpdbg_is_auto_global(char *name, int len);
 
 PHPDBG_API void phpdbg_xml_var_dump(zval *zv);
 
-PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex);
+PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex, zend_object *exception);
 
 #ifdef ZTS
 #define PHPDBG_OUTPUT_BACKUP_DEFINES() \