Skip to content

Commit a505fc6

Browse files
committed
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.
1 parent a87d620 commit a505fc6

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,16 +1046,17 @@ static inline int ct_eval_func_call(
10461046
for (i = 0; i < num_args; i++) {
10471047
zval_ptr_dtor_nogc(EX_VAR_NUM(i));
10481048
}
1049-
efree(execute_data);
1050-
EG(current_execute_data) = prev_execute_data;
10511049

1050+
int retval = SUCCESS;
10521051
if (EG(exception)) {
10531052
zval_ptr_dtor(result);
10541053
zend_clear_exception();
1055-
return FAILURE;
1054+
retval = FAILURE;
10561055
}
10571056

1058-
return SUCCESS;
1057+
efree(execute_data);
1058+
EG(current_execute_data) = prev_execute_data;
1059+
return retval;
10591060
}
10601061

10611062
#define SET_RESULT(op, zv) do { \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
var_dump(version_compare('1.2', '2.1', '??'));
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Exception thrown during SCCP evaluation, separate file variation
3+
--FILE--
4+
<?php
5+
require __DIR__ . '/sccp_exception2.inc';
6+
?>
7+
--EXPECTF--
8+
Fatal error: Uncaught ValueError: version_compare(): Argument #3 ($operator) must be a valid comparison operator in %s:%d
9+
Stack trace:
10+
#0 %s(%d): version_compare('1.2', '2.1', '??')
11+
#1 %s(%d): require('/home/nikic/php...')
12+
#2 {main}
13+
thrown in %s on line %d

0 commit comments

Comments
 (0)