Skip to content

Commit 34f07c5

Browse files
committed
Fix use-after-free of object through __isset() and globals
Fixes phpGH-18845
1 parent 2e2494f commit 34f07c5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Zend/tests/gh18845.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-18845: Use-after-free of object through __isset() and globals
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public function __isset($x) {
8+
$GLOBALS['c'] = null;
9+
return true;
10+
}
11+
}
12+
13+
$c = new C;
14+
var_dump($c->prop ?? 1);
15+
16+
?>
17+
--EXPECT--
18+
int(1)

Zend/zend_object_handlers.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,13 @@ ZEND_API zval *zend_std_read_property(zend_object *zobj, zend_string *name, int
905905
if (zobj->ce->__get && !((*guard) & IN_GET)) {
906906
goto call_getter;
907907
}
908+
909+
bool obj_is_freed = GC_REFCOUNT(zobj) == 1;
908910
OBJ_RELEASE(zobj);
911+
if (UNEXPECTED(obj_is_freed)) {
912+
retval = &EG(uninitialized_zval);
913+
goto exit;
914+
}
909915
} else if (zobj->ce->__get && !((*guard) & IN_GET)) {
910916
goto call_getter_addref;
911917
}

0 commit comments

Comments
 (0)