You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I edit a public function on bot A while a program that uses it is running on bot B, this (in some cases) leads to a crash. This is because the function is replaced after I edit it and bot B now tries to run the updated function, but the stack was populated by the previous version of the function. This may lead to a violation of invariants expected by CBot instructions and weird behaviour or even a crash. I constructed one example, but I am sure many more can be constructed - every instruction has it's own invariants.
Example
Load this into bot A:
public void Foo()
{
{
{
{}
while(true);
}
}
}
Run this in bot B:
extern void New()
{
Foo();
}
Replace the program in bot A with:
public void Foo()
{
message("hello");
}
The game crashes - segmentation fault (null pointer dereference)
Why? Because the code that creates a CBotVar to hold the return value of message() got skipped. We now have a null where a CBotVar was expected.
Thoughts about a fix
We could handle the stack very defensively - don't assume it preserves any invariants. The downside is that this bug becomes a "whack-a-mole" - many edge cases like the example above probably exist - we have no way to know if we fixed them all. Also: this approach may substantially increase the complexity of the already hard-to-understand code in CBot/src/CBot/CBotInstr/
We could make copies of the public functions used by a program when it starts executing. Then the code will not change while it is running. The downside is that we have to somehow handle the game being saved and reloaded - the copies in memory are not enough - we would have to save the copies to disk as well.
We could just stop all CBot programs that use a public function when the function is edited.
If I edit a public function on bot A while a program that uses it is running on bot B, this (in some cases) leads to a crash. This is because the function is replaced after I edit it and bot B now tries to run the updated function, but the stack was populated by the previous version of the function. This may lead to a violation of invariants expected by CBot instructions and weird behaviour or even a crash. I constructed one example, but I am sure many more can be constructed - every instruction has it's own invariants.
Example
Why? Because the code that creates a CBotVar to hold the return value of message() got skipped. We now have a null where a CBotVar was expected.
Thoughts about a fix
CBot/src/CBot/CBotInstr/
Related
The text was updated successfully, but these errors were encountered: