Skip to content

Commit eca7494

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix uaf for nested finally with repeated return type check
2 parents e85550f + ac0dc98 commit eca7494

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Zend/tests/oss_fuzz_438780145.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
OSS-Fuzz #438780145: Nested finally with repeated return type check may uaf
3+
--FILE--
4+
<?php
5+
6+
function &test(): int {
7+
$x = 0;
8+
try {
9+
return $x;
10+
} finally {
11+
try {
12+
return $x;
13+
} finally {
14+
$x = "";
15+
}
16+
}
17+
}
18+
19+
test();
20+
21+
?>
22+
--EXPECTF--
23+
Fatal error: Uncaught TypeError: test(): Return value must be of type int, string returned in %s:%d
24+
Stack trace:
25+
#0 %s(%d): test()
26+
#1 {main}
27+
thrown in %s on line %d

Zend/zend_vm_def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8624,6 +8624,10 @@ ZEND_VM_HANDLER(159, ZEND_DISCARD_EXCEPTION, ANY, ANY)
86248624
zval *return_value = EX_VAR(EX(func)->op_array.opcodes[Z_OPLINE_NUM_P(fast_call)].op2.var);
86258625

86268626
zval_ptr_dtor(return_value);
8627+
/* Clear return value in case we hit both DISCARD_EXCEPTION and
8628+
* zend_dispatch_try_catch_finally_helper, which will free the return
8629+
* value again. See OSS-Fuzz #438780145. */
8630+
ZVAL_NULL(return_value);
86278631
}
86288632

86298633
/* cleanup delayed exception */

Zend/zend_vm_execute.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)