]> granicus.if.org Git - php/commitdiff
Fixed bug #79777
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 4 Jul 2020 07:59:42 +0000 (09:59 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 4 Jul 2020 07:59:42 +0000 (09:59 +0200)
Zend/tests/die_string_cast_exception.phpt [new file with mode: 0644]
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/die_string_cast_exception.phpt b/Zend/tests/die_string_cast_exception.phpt
new file mode 100644 (file)
index 0000000..9893c33
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #79777: String cast exception during die should be handled gracefully
+--FILE--
+<?php
+
+die(new stdClass);
+
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in %s:%d
+Stack trace:
+#0 {main}
+  thrown in %s on line %d
index 241c56851c6c8d0acc9109b2d1f5d63d30fc3971..c316795450fe03d54ade200599d7792542a36331 100644 (file)
@@ -6893,7 +6893,10 @@ ZEND_VM_COLD_HANDLER(79, ZEND_EXIT, ANY, ANY)
                } while (0);
                FREE_OP1();
        }
-       zend_throw_unwind_exit();
+
+       if (!EG(exception)) {
+               zend_throw_unwind_exit();
+       }
        HANDLE_EXCEPTION();
 }
 
index c1975fd0b9ae1cf760fffe9090fb859fc11408dc..67f1c0d61522902b5d305346e2b084b6711a3828 100644 (file)
@@ -2322,7 +2322,10 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_HANDLER
                } while (0);
                FREE_OP(opline->op1_type, opline->op1.var);
        }
-       zend_throw_unwind_exit();
+
+       if (!EG(exception)) {
+               zend_throw_unwind_exit();
+       }
        HANDLE_EXCEPTION();
 }
 
@@ -2476,7 +2479,6 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_dispatch_try
 {
        /* May be NULL during generator closing (only finally blocks are executed) */
        zend_object *ex = EG(exception);
-       zend_bool is_unwind_exit = ex && zend_is_unwind_exit(ex);
 
        /* Walk try/catch/finally structures upwards, performing the necessary actions */
        for (; try_catch_offset != (uint32_t) -1; try_catch_offset--) {
@@ -2489,7 +2491,7 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_dispatch_try
                        ZEND_VM_JMP_EX(&EX(func)->op_array.opcodes[try_catch->catch_op], 0);
 
                } else if (op_num < try_catch->finally_op) {
-                       if (is_unwind_exit) {
+                       if (ex && zend_is_unwind_exit(ex)) {
                                /* Don't execute finally blocks on exit (for now) */
                                continue;
                        }