Merge branch 'PHP-8.2'

* PHP-8.2:
  Fix GH-10709: UAF in recursive AST evaluation
This commit is contained in:
Ilija Tovilo 2023-03-06 15:03:19 +01:00
commit 9944f58d3f
No known key found for this signature in database
GPG key ID: A4F5D403F118200A
6 changed files with 109 additions and 1 deletions

View file

@ -698,7 +698,19 @@ ZEND_API zend_result ZEND_FASTCALL zval_update_constant_with_ctx(zval *p, zend_c
zval tmp;
bool short_circuited;
if (UNEXPECTED(zend_ast_evaluate_ex(&tmp, ast, scope, &short_circuited, ctx) != SUCCESS)) {
// Increase the refcount during zend_ast_evaluate to avoid releasing the ast too early
// on nested calls to zval_update_constant_ex which can happen when retriggering ast
// evaluation during autoloading.
zend_ast_ref *ast_ref = Z_AST_P(p);
bool ast_is_refcounted = !(GC_FLAGS(ast_ref) & GC_IMMUTABLE);
if (ast_is_refcounted) {
GC_ADDREF(ast_ref);
}
zend_result result = zend_ast_evaluate_ex(&tmp, ast, scope, &short_circuited, ctx) != SUCCESS;
if (ast_is_refcounted && !GC_DELREF(ast_ref)) {
rc_dtor_func((zend_refcounted *)ast_ref);
}
if (UNEXPECTED(result != SUCCESS)) {
return FAILURE;
}
zval_ptr_dtor_nogc(p);