Skip to content

Fix use-after-free of name in var-var with malicious error handler #12732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Zend/tests/oss_fuzz_54325.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
oss-fuzz #54325: Fix use-after-free of name in var-var with malicious error handler
--FILE--
<?php
set_error_handler(function ($errno, $errstr) {
var_dump($errstr);
global $x;
$x = new stdClass;
});

// Needs to be non-interned string
$x = strrev('foo');
$$x++;
var_dump($x);
?>
--EXPECT--
string(23) "Undefined variable $oof"
object(stdClass)#2 (0) {
}
7 changes: 7 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -1748,13 +1748,20 @@ ZEND_VM_C_LABEL(fetch_this):
} else if (type == BP_VAR_IS || type == BP_VAR_UNSET) {
retval = &EG(uninitialized_zval);
} else {
if (OP1_TYPE == IS_CV) {
/* Keep name alive in case an error handler tries to free it. */
zend_string_addref(name);
}
zend_error(E_WARNING, "Undefined %svariable $%s",
(opline->extended_value & ZEND_FETCH_GLOBAL ? "global " : ""), ZSTR_VAL(name));
if (type == BP_VAR_RW && !EG(exception)) {
retval = zend_hash_update(target_symbol_table, name, &EG(uninitialized_zval));
} else {
retval = &EG(uninitialized_zval);
}
if (OP1_TYPE == IS_CV) {
zend_string_release(name);
}
}
/* GLOBAL or $$name variable may be an INDIRECT pointer to CV */
} else if (Z_TYPE_P(retval) == IS_INDIRECT) {
Expand Down
21 changes: 21 additions & 0 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.