Skip to content

lua_pcall/lua_error invocations might be unsafe (all of them) #21

Closed
@jonas-schievink

Description

@jonas-schievink

Currently, rlua makes sure to only call Lua API functions that can cause an error from within error_guard, which uses lua_pcall to run a Rust closure in a protected environment. This causes all Lua errors to be caught by lua_pcall.

Since Lua's error handling uses setjmp and longjmp to do non-local control flow, an error will longjmp to the lua_pcall, skipping across the Rust closure passed to error_guard. According to IRC this is undefined behaviour in Rust. EDIT: People are also claiming that it's unsafe in this user forum thread.

Fixing this is hard. It would require that all uses of lua_pcall only call C functions. And calling lua_error from Rust would never be a safe thing to do, since it must skip across a Rust stack frame.

If this is really UB, the only way to write a safe Lua wrapper would involve writing C code. Not sure if that's really the case, though...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions