From 5a10dec6985c2d40a9953a3a727d0a9333ec72bf Mon Sep 17 00:00:00 2001 From: Christiano Becker Date: Mon, 16 Jan 2023 17:35:07 -0300 Subject: [PATCH] When FLAG_PROPAGATE_PHP_EXCEPTIONS is set, check for unwind or graceful exit before propagate --- tests/issue_497_001.phpt | 37 +++++++++++++++++++++++++++++++++++++ v8js_object_export.cc | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/issue_497_001.phpt diff --git a/tests/issue_497_001.phpt b/tests/issue_497_001.phpt new file mode 100644 index 0000000..deb3daf --- /dev/null +++ b/tests/issue_497_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test V8::executeString() : Issue #497 (segmentation fault calling PHP exit inside object function) +--SKIPIF-- + +--FILE-- +foo = new Foo(); + +$JS = <<< EOT +PHP.foo.somecall(); +PHP.foo.bar(); +EOT; + +$v8->executeString($JS, '', \V8JS::FLAG_PROPAGATE_PHP_EXCEPTIONS); +echo 'Not here!!'; +?> +--EXPECTF-- +string(12) "Foo somecall" +string(7) "Foo bar" +string(14) "Foo __destruct" diff --git a/v8js_object_export.cc b/v8js_object_export.cc index 78597d0..ebbabde 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -167,7 +167,7 @@ failure: } if(EG(exception)) { - if(ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) { + if((ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) && !zend_is_graceful_exit(EG(exception)) && !zend_is_unwind_exit(EG(exception))) { zval tmp_zv; ZVAL_OBJ(&tmp_zv, EG(exception)); return_value = isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate));