mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Merge branch 'PHP-8.3'
* PHP-8.3: Fix use-after-free in property coercion with __toString()
This commit is contained in:
47
Zend/tests/gh14969.phpt
Normal file
47
Zend/tests/gh14969.phpt
Normal file
@@ -0,0 +1,47 @@
|
||||
--TEST--
|
||||
GH-14969: Crash on coercion with throwing __toString()
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class C {
|
||||
public function __toString() {
|
||||
global $c;
|
||||
$c = [];
|
||||
throw new Exception(__METHOD__);
|
||||
}
|
||||
}
|
||||
|
||||
class D {
|
||||
public string $prop;
|
||||
}
|
||||
|
||||
$c = new C();
|
||||
$d = new D();
|
||||
try {
|
||||
$d->prop = $c;
|
||||
} catch (Throwable $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
var_dump($d);
|
||||
|
||||
$c = new C();
|
||||
$d->prop = 'foo';
|
||||
try {
|
||||
$d->prop = $c;
|
||||
} catch (Throwable $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
var_dump($d);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
C::__toString
|
||||
object(D)#%d (0) {
|
||||
["prop"]=>
|
||||
uninitialized(string)
|
||||
}
|
||||
C::__toString
|
||||
object(D)#2 (1) {
|
||||
["prop"]=>
|
||||
string(3) "foo"
|
||||
}
|
||||
@@ -974,7 +974,7 @@ typed_property:
|
||||
goto exit;
|
||||
}
|
||||
if (UNEXPECTED(!type_matched)) {
|
||||
Z_TRY_DELREF_P(value);
|
||||
zval_ptr_dtor(&tmp);
|
||||
variable_ptr = &EG(error_zval);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user