[BUG?] Segmentation fault in lua_error() - easily reproducible

  • From: "Sergei Zhirikov" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "sfzhi@xxxxxxxxx" for DMARC)
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 12 Dec 2014 20:44:27 +0000 (UTC)

Hi,
I've encountered this case of a consistent segmentation fault in LuaJIT (tested 
with 2.0.3 on x86 and x86_64).The following simple example allows to reproduce 
it:
#include <lua.h>#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>

int main()
{
  lua_State *lua = luaL_newstate();
  luaL_openlibs(lua);
  luaL_loadstring(lua, "coroutine.yield()");
  int res = lua_resume(lua, 0);
  printf("res=%d, top=%d\n", res, lua_gettop(lua));
  lua_pushliteral(lua, "test");
  lua_error(lua);
  return 0;
}

This code is supposed to panic, but it results in a segmentation fault inside 
lua_error() instead. Admittedly, this not a very common usage pattern, but 
calling lua_error() on a suspended Lua thread can be useful sometimes. Also, 
the "classic" Lua implementation doesn't have a problem with this usage.
I'm wondering, can this be fixed with a simple patch?
Thanks & regards,
Sergei.


Other related posts:

  • » [BUG?] Segmentation fault in lua_error() - easily reproducible - Sergei Zhirikov