tomaka / hlua

Rust library to interface with Lua
MIT License
510 stars 48 forks source link

Undefined behavior on allocation failure #133

Open DemiMarie opened 7 years ago

DemiMarie commented 7 years ago

Like most other Lua binding libs, hlua runs into undefined behavior whenever a call to Lua raises a memory allocation error. The undefined behavior appears as a result of longjmping across Rust stack frames.

One solution is to provide the Lua state an allocation function which aborts on failure, preventing Lua from ever raising a memory allocation error. However, this prevents valid use cases, such as running Lua code in a sandbox with restricted memory use.

A better solution is to ensure that every call into Lua that may throw an error is wrapped in lua_pcall. This won't be easy