Skip to content

Commit b965f15

Browse files
committed
Fix use-after-free when trying to write to closure property
1 parent ee89e73 commit b965f15

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Zend/tests/closure_write_prop.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Cannot write to closure properties
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
function getFn() {
8+
return function() {
9+
};
10+
}
11+
}
12+
13+
$a = new A;
14+
try {
15+
$c = $a->getFn()->b = new stdClass;
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Closure object cannot have properties

Zend/zend_closures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static ZEND_COLD zval *zend_closure_read_property(zval *object, zval *member, in
435435
static ZEND_COLD zval *zend_closure_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */
436436
{
437437
ZEND_CLOSURE_PROPERTY_ERROR();
438-
return value;
438+
return &EG(error_zval);
439439
}
440440
/* }}} */
441441

0 commit comments

Comments
 (0)