Merge branch 'PHP-8.1' into PHP-8.2

* PHP-8.1:
  Fix segfault when using ReflectionFiber (fixes #10439)
This commit is contained in:
Ilija Tovilo 2023-02-23 23:27:55 +01:00
commit f1818d726f
No known key found for this signature in database
GPG Key ID: A4F5D403F118200A
6 changed files with 115 additions and 7 deletions

2
NEWS
View File

@ -67,6 +67,8 @@ PHP NEWS
- Reflection:
. Fixed bug GH-10623 (Reflection::getClosureUsedVariables opcode fix with
variadic arguments). (nielsdos)
. Fix Segfault when using ReflectionFiber suspended by an internal function.
(danog)
- Session:
. Fixed ps_files_cleanup_dir() on failure code paths with -1 instead of 0 as

View File

@ -7085,7 +7085,13 @@ ZEND_METHOD(ReflectionFiber, getExecutingLine)
prev_execute_data = fiber->execute_data->prev_execute_data;
}
RETURN_LONG(prev_execute_data->opline->lineno);
while (prev_execute_data && (!prev_execute_data->func || !ZEND_USER_CODE(prev_execute_data->func->common.type))) {
prev_execute_data = prev_execute_data->prev_execute_data;
}
if (prev_execute_data && prev_execute_data->func && ZEND_USER_CODE(prev_execute_data->func->common.type)) {
RETURN_LONG(prev_execute_data->opline->lineno);
}
RETURN_NULL();
}
ZEND_METHOD(ReflectionFiber, getExecutingFile)
@ -7103,7 +7109,13 @@ ZEND_METHOD(ReflectionFiber, getExecutingFile)
prev_execute_data = fiber->execute_data->prev_execute_data;
}
RETURN_STR_COPY(prev_execute_data->func->op_array.filename);
while (prev_execute_data && (!prev_execute_data->func || !ZEND_USER_CODE(prev_execute_data->func->common.type))) {
prev_execute_data = prev_execute_data->prev_execute_data;
}
if (prev_execute_data && prev_execute_data->func && ZEND_USER_CODE(prev_execute_data->func->common.type)) {
RETURN_STR_COPY(prev_execute_data->func->op_array.filename);
}
RETURN_NULL();
}
ZEND_METHOD(ReflectionFiber, getCallable)

View File

@ -874,9 +874,9 @@ final class ReflectionFiber
public function getFiber(): Fiber {}
public function getExecutingFile(): string {}
public function getExecutingFile(): ?string {}
public function getExecutingLine(): int {}
public function getExecutingLine(): ?int {}
public function getCallable(): callable {}

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a531c9132b4ac3d3196570ae6dda52b8f6a4f488 */
* Stub hash: b247a6a7fed18525f611001da064da58e7583501 */
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 1, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@ -593,9 +593,11 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ReflectionFiber_getFiber, 0, 0, Fiber, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionFiber_getExecutingFile arginfo_class_ReflectionFunction___toString
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFiber_getExecutingFile, 0, 0, IS_STRING, 1)
ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionFiber_getExecutingLine arginfo_class_ReflectionAttribute_getTarget
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFiber_getExecutingLine, 0, 0, IS_LONG, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFiber_getCallable, 0, 0, IS_CALLABLE, 0)
ZEND_END_ARG_INFO()

View File

@ -0,0 +1,31 @@
--TEST--
ReflectionFiber should not segfault when inspecting fibers with no stack frames before suspend
--FILE--
<?php
$f = new Fiber(Fiber::suspend(...));
$f->start();
$reflection = new ReflectionFiber($f);
var_dump($reflection->getExecutingFile());
var_dump($reflection->getExecutingLine());
var_dump($reflection->getTrace());
?>
--EXPECTF--
NULL
NULL
array(1) {
[0]=>
array(4) {
["function"]=>
string(7) "suspend"
["class"]=>
string(5) "Fiber"
["type"]=>
string(2) "::"
["args"]=>
array(0) {
}
}
}

View File

@ -0,0 +1,61 @@
--TEST--
ReflectionFiber should not segfault when inspecting fibers where the previous stack frame is a native function
--FILE--
<?php
namespace test;
$f = new \Fiber(fn() => call_user_func(["Fiber", "suspend"]));
$f->start();
$reflection = new \ReflectionFiber($f);
var_dump($reflection->getExecutingFile());
var_dump($reflection->getExecutingLine());
var_dump($reflection->getTrace());
?>
--EXPECTF--
string(%d) "%sReflectionFiber_notrace_2.php"
int(5)
array(3) {
[0]=>
array(4) {
["function"]=>
string(7) "suspend"
["class"]=>
string(5) "Fiber"
["type"]=>
string(2) "::"
["args"]=>
array(0) {
}
}
[1]=>
array(4) {
["file"]=>
string(%d) "%sReflectionFiber_notrace_2.php"
["line"]=>
int(5)
["function"]=>
string(14) "call_user_func"
["args"]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(5) "Fiber"
[1]=>
string(7) "suspend"
}
}
}
[2]=>
array(2) {
["function"]=>
string(14) "test\{closure}"
["args"]=>
array(0) {
}
}
}