-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Fix GH-17941: Stack-use-after-return with lazy objects and hooks #17947
Conversation
zend_std_write_property() can return the variable pointer, but the code was using a local variable, and so a pointer to a local variable could be returned. Fix this by using the value pointer instead of the backup value was written. This can be more efficient on master by using the safe_assign helper.
Actually, now the value between variable_ptr and value can be inconsistent. And it's a bit annoying that we can't "just" add a reference because the backupping of the value influences the semantics (i.e. is observable). I'm not going to deal with this. |
I think the observable semantic change is right, because the current behavior is wrong. Currently,
In the first case, when Your change makes the behavior consistent, so I think it's right. |
Okay, reopening for review then. I closed it because I didn't see an easy way to make the behaviour the same and didn't want to deal with this, but if the new behaviour is right then sure. |
I found another issue: class C {
public $prop {
set {
echo "set\n";
$this->prop = $value * 2;
}
}
}
$rc = new ReflectionClass(C::class);
$obj = $rc->newLazyProxy(function () {
echo "init\n";
return new C;
});
function foo(C $c) {
$c->prop = 1;
var_dump($c->prop);
}
foo($obj);
As you can see, the original
WDYT? |
My poor head... Option 2 sounds best, I have yet to dig into the code that deals with proxies though. The first option would be bad because of observable side effects. |
I also prefer the second approach, as it’s what would happen if the hook was a method. It’s consistent with how lazy objects are specified: Interaction with the proxy executes the proxy’s code, and property accesses forward to the real instance. A third approach would have been to initialize before calling the hook, and to call the hook on the real instance. But the second approach is better. Potentially this can be fixed separately. @nielsdos I can take care of it if you don’t want to. |
Yes, I still prefer the second approach as well, it's the most logical.
I agree this may be fixed separately. Feel free to give it a shot, I'm kinda busy right now 🙂 |
Handling this separately sounds good to me! Feel free to merge this one, I'll create a new issue. @arnaud-lb |
Thank you @nielsdos! |
zend_std_write_property() can return the variable pointer, but the code
was using a local variable, and so a pointer to a local variable could
be returned. Fix this by using the value pointer instead of the backup
value was written.