Skip to content
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

Accessing table field with the wrong user type causes a segmentation fault #1595

Open
gotschmarcel-ni opened this issue Apr 11, 2024 · 0 comments

Comments

@gotschmarcel-ni
Copy link
Contributor

Accessing table field with the wrong user type causes a segmentation fault.

Context

Language: C++
Sol Version: 3.3.0
Defines: SOL_ALL_SAFETIES_ON, SOL_USE_CXX_LUA

Reproduction

Godbolt, which doesn't can't use SOL_USE_CXX_LUA.

#include <sol/sol.hpp>
#include <iostream>

struct T {};
struct C {};

int main() {
    sol::state lua;

    lua.new_usertype<T>("T", "new", []{ return T{}; });
    sol::table tbl = lua.script("return { t = T.new() }");

    try {
        tbl.get<C>("t");
    } catch (const sol::error& error) {
       std::cout << "Whoops: " << error.what() << '\n';
    }
}

Expectation

get should throw an error that can be caught and handled.

Debugging Context

When debugging this issue, we've identified that the problem is caused by the clean helper created here. It calls lua_pop in it's destructor which tries to call __close on some object, but __close is nil, raising a subsequent panic which results in a throw in a C++ destructor of clean which will call terminate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant