-
Notifications
You must be signed in to change notification settings - Fork 117
Segfault on dropping LuaFunction? #82
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
Comments
This shouldn't compile, this is 100% a soundness issue, and I have a fix incoming... I think. I need to do a lot more testing to make sure this fix is right. As soon as I fix the soundness issue, I'll help you through what you're trying to do, because like I said this SHOULDN'T compile, but it does because of a really bad issue :( This is a GREAT find, thank you so much for finding this :( |
I think a2615a8 fixes this issue, in that the example program you gave no longer compiles and there is now a compiletest_rs test for this specific issue. The issue allowed parameters passed to callbacks created from This was only a problem inside This fix probably doesn't help your actual problem, since it just makes this example not compile. The good news is you might not need |
Thanks so much for the explanation! I guess I thought that Rust references to Lua values could be carried around as long as the top-level The struct StoredFunction<'a>(&'a Lua, Option<LuaRegistryKey>);
impl<'a> StoredFunction<'a> {
pub fn new(lua :&'a Lua, f :LuaFunction) -> LuaResult<StoredFunction<'a>> {
Ok(StoredFunction(lua, Some(lua.create_registry_value(f)?)))
}
pub fn call<A: rlua::ToLuaMulti<'a>, R: rlua::FromLuaMulti<'a>>(&self, args: A) -> LuaResult<R> {
self.0.registry_value::<LuaFunction>(self.1.as_ref().expect("Stored function error"))
.and_then(|x| x.call(args))
}
}
impl<'a> Drop for StoredFunction<'a> {
fn drop(&mut self) {
self.0.remove_registry_value(self.1.take().unwrap()).unwrap();
}
} |
There are actually multiple If you're okay with storing a a I know the handle based API has some limitations and sometimes you could envision the API without those limitations, but generally this is because handles are just not designed to be stored inside Lua itself, so anything involving capturing them in callbacks or getting them out of callbacks is probably going to be painful. |
In the meantime, I have found another soundness bug along the same lines with a closure capturing its own arguments into an owned value rather than a captured reference, and have had to attempt another fix (1a9c50f). If anybody is confident in their lifetime knowledge and wants to test this out and try to break it, I would be very appreciative, because I'm not very confident there isn't another issue here. I at least have coverage of all the issues with compiletest_rs, but I would really appreciate another set of eyes here. |
I went ahead and released 0.14.2 as well with the second fix, hopefully I'm not missing any other safety issues here. |
Great, thanks again for your help. Just for information, I went ahead with storing the functions in a global table on the Lua side, and then creating a |
Hello, and thanks for this library, it looks great.
I'm trying to write a configurable/scriptable program where one can register functions from a Lua script to be used later from a GUI Rust program. Running the following in release mode (Linux 64 bit, Rust 1.27.2) creates a segfault when
program
is dropped. Am I doing something wrong or strange?GDB output:
The text was updated successfully, but these errors were encountered: