-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler #12114
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
Conversation
Zend/zend_object_handlers.c
Outdated
| zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); | ||
| /* We set the retval to null AFTER the warning so that an error handler cannot mess | ||
| * with the property value... */ | ||
| ZVAL_NULL(retval); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can leak.
class Foo {}
class C {
public $a;
function errorHandler($errno, $errstr) {
$this->a = new Foo();
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
(++$c->a);
var_dump($c->a);Just wrapping the ZVAL_NULL in a if (Z_TYPE_P(retval) == IS_UNDEF) { should do. This will change the behavior to throw a "TypeError: Cannot increment Foo" exception, which I think is what I would expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if we want that, then for consistency the zend_hash_update for the dynamic case should become zend_hash_add instead too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nielsdos That probably makes sense. The leak doesn't happen in that case because the hash table takes care of releasing the old value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK ty, I'll make a PR soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
962e84f to
28df23b
Compare
With the fix in php#12114, the behaviour would change for non-dynamic properties. Align the behaviour for dynamic properties to be the same.
dstogov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine
…at is unset in error handler Reorder when we assign the property value to NULL which is identical to a3a3964 Just for the declared property case instead of dynamic.
28df23b to
9c123ac
Compare
Reorder when we assign the property value to NULL which is identical to a3a3964
Just for the declared property case instead of dynamic.