From a505fc627ecd4c146e10e05995816fba14f1f1b6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 27 Nov 2020 17:43:24 +0100 Subject: Fix handling of sccp exceptions We should clear the exception *before* we destroy the execute_data. Add a variation of the test that indirects through another file, and would crash otherwise. --- ext/opcache/Optimizer/sccp.c | 9 +++++---- ext/opcache/tests/opt/sccp_exception2.inc | 2 ++ ext/opcache/tests/opt/sccp_exception2.phpt | 13 +++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 ext/opcache/tests/opt/sccp_exception2.inc create mode 100644 ext/opcache/tests/opt/sccp_exception2.phpt (limited to 'ext/opcache') diff --git a/ext/opcache/Optimizer/sccp.c b/ext/opcache/Optimizer/sccp.c index 1c4330717b..9f122296f5 100644 --- a/ext/opcache/Optimizer/sccp.c +++ b/ext/opcache/Optimizer/sccp.c @@ -1046,16 +1046,17 @@ static inline int ct_eval_func_call( for (i = 0; i < num_args; i++) { zval_ptr_dtor_nogc(EX_VAR_NUM(i)); } - efree(execute_data); - EG(current_execute_data) = prev_execute_data; + int retval = SUCCESS; if (EG(exception)) { zval_ptr_dtor(result); zend_clear_exception(); - return FAILURE; + retval = FAILURE; } - return SUCCESS; + efree(execute_data); + EG(current_execute_data) = prev_execute_data; + return retval; } #define SET_RESULT(op, zv) do { \ diff --git a/ext/opcache/tests/opt/sccp_exception2.inc b/ext/opcache/tests/opt/sccp_exception2.inc new file mode 100644 index 0000000000..896d89dde2 --- /dev/null +++ b/ext/opcache/tests/opt/sccp_exception2.inc @@ -0,0 +1,2 @@ + +--EXPECTF-- +Fatal error: Uncaught ValueError: version_compare(): Argument #3 ($operator) must be a valid comparison operator in %s:%d +Stack trace: +#0 %s(%d): version_compare('1.2', '2.1', '??') +#1 %s(%d): require('/home/nikic/php...') +#2 {main} + thrown in %s on line %d -- cgit v1.2.1