Skip to content

Commit 3ab6e76

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference Fix GH-8841: php-cli core dump calling a badly formed function
2 parents ed0b773 + dd29b66 commit 3ab6e76

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed

Zend/tests/gh8841.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
GH-8841 (php-cli core dump calling a badly formed function)
3+
--FILE--
4+
<?php
5+
register_shutdown_function(function() {
6+
echo "Before calling g()\n";
7+
g(1);
8+
echo "After calling g()\n";
9+
});
10+
11+
register_shutdown_function(function() {
12+
echo "Before calling f()\n";
13+
f(1);
14+
echo "After calling f()\n";
15+
});
16+
17+
eval('function g($x): int { return $x; }');
18+
eval('function f($x): void { return $x; }');
19+
?>
20+
--EXPECTF--
21+
Fatal error: A void function must not return a value in %s on line %d
22+
Before calling g()
23+
After calling g()
24+
Before calling f()
25+
26+
Fatal error: Uncaught Error: Call to undefined function f() in %s:%d
27+
Stack trace:
28+
#0 [internal function]: {closure}()
29+
#1 {main}
30+
thrown in %s on line %d

Zend/zend_compile.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7409,11 +7409,7 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
74097409
}
74107410

74117411
zend_register_seen_symbol(lcname, ZEND_SYMBOL_FUNCTION);
7412-
if (toplevel) {
7413-
if (UNEXPECTED(zend_hash_add_ptr(CG(function_table), lcname, op_array) == NULL)) {
7414-
do_bind_function_error(lcname, op_array, 1);
7415-
}
7416-
} else {
7412+
if (!toplevel) {
74177413
uint32_t func_ref = zend_add_dynamic_func_def(op_array);
74187414
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
74197415
opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL);
@@ -7438,7 +7434,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
74387434
zend_ast *stmt_ast = decl->child[2];
74397435
zend_ast *return_type_ast = decl->child[3];
74407436
bool is_method = decl->kind == ZEND_AST_METHOD;
7441-
zend_string *lcname = NULL;
7437+
zend_string *lcname;
74427438

74437439
zend_class_entry *orig_class_entry = CG(active_class_entry);
74447440
zend_op_array *orig_op_array = CG(active_op_array);
@@ -7542,6 +7538,11 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
75427538
CG(zend_lineno) = decl->start_lineno;
75437539
zend_check_magic_method_implementation(
75447540
CG(active_class_entry), (zend_function *) op_array, lcname, E_COMPILE_ERROR);
7541+
} else if (toplevel) {
7542+
/* Only register the function after a successful compile */
7543+
if (UNEXPECTED(zend_hash_add_ptr(CG(function_table), lcname, op_array) == NULL)) {
7544+
do_bind_function_error(lcname, op_array, true);
7545+
}
75457546
}
75467547

75477548
/* put the implicit return on the really last line */

ext/reflection/php_reflection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4642,7 +4642,7 @@ ZEND_METHOD(ReflectionClass, getProperties)
46424642
if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) {
46434643
HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(Z_OBJ(intern->obj));
46444644
zval *prop;
4645-
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, prop) {
4645+
ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) {
46464646
_adddynproperty(prop, key, ce, return_value);
46474647
} ZEND_HASH_FOREACH_END();
46484648
}

ext/simplexml/tests/gh10983.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-10983 (State-dependant segfault in ReflectionObject::getProperties)
3+
--EXTENSIONS--
4+
simplexml
5+
--FILE--
6+
<?php
7+
8+
$xml = <<<XML
9+
<form name="test"></form>
10+
XML;
11+
12+
$simplexml = simplexml_load_string($xml);
13+
14+
var_dump($simplexml['name']);
15+
$reflector = new ReflectionObject($simplexml['name']);
16+
$rprops = $reflector->getProperties();
17+
18+
?>
19+
--EXPECT--
20+
object(SimpleXMLElement)#2 (1) {
21+
[0]=>
22+
string(4) "test"
23+
}

ext/standard/mail.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static void php_mail_build_headers_elems(smart_str *s, zend_string *key, zval *v
136136
zend_type_error("Header \"%s\" must only contain numeric keys, \"%s\" found", ZSTR_VAL(key), ZSTR_VAL(tmp_key));
137137
break;
138138
}
139+
ZVAL_DEREF(tmp_val);
139140
if (Z_TYPE_P(tmp_val) != IS_STRING) {
140141
zend_type_error("Header \"%s\" must only contain values of type string, %s found", ZSTR_VAL(key), zend_zval_value_name(tmp_val));
141142
break;
@@ -157,6 +158,7 @@ PHPAPI zend_string *php_mail_build_headers(HashTable *headers)
157158
zend_type_error("Header name cannot be numeric, " ZEND_LONG_FMT " given", idx);
158159
break;
159160
}
161+
ZVAL_DEREF(val);
160162
/* https://tools.ietf.org/html/rfc2822#section-3.6 */
161163
if (zend_string_equals_literal_ci(key, "orig-date")) {
162164
PHP_MAIL_BUILD_HEADER_CHECK("orig-date", s, key, val);

ext/standard/tests/mail/gh10990.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-10990 (mail() throws TypeError after iterating over $additional_headers array by reference)
3+
--INI--
4+
sendmail_path=rubbish 2>/dev/null
5+
--SKIPIF--
6+
<?php
7+
if(substr(PHP_OS, 0, 3) == "WIN")
8+
die("skip Won't run on Windows");
9+
?>
10+
--FILE--
11+
<?php
12+
13+
$headers = ['From' => &$from];
14+
var_dump(mail('[email protected]', 'Test', 'Test', $headers));
15+
?>
16+
--EXPECT--
17+
bool(false)

0 commit comments

Comments
 (0)