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

  • From: imzyxwvu@xxxxxxxxx
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Mon, 15 Dec 2014 11:09:06 +0800

Maybe my previous statements made people feel uncomfortable. I'm sorry. Did you 
see that undefined? I said it because in the Lua side error API takes no thread 
and throws error always on the current thread. If a coroutine is yielded it 
couldn't throw any error. 

Now I admit I was wrong. I was limited by classical usages. I agree with Sergei 
that it is a bug.

I think seen at the thread the error was just thrown by the coroutine.yield() 
and it was not caught by any pcall so at last it would lead to a Lua panic. 
Please tell me if my sense about this report is right now. Thanks.

> 在 2014年12月15日,9:56,Sean Conner <sean@xxxxxxxxxx> 写道:
> 
> It was thus said that the Great imzyxwvu@xxxxxxxxx once stated:
>>> 在 2014年12月14日,17:38,"Sergei Zhirikov" <dmarc-noreply@xxxxxxxxxxxxx> 
>>> (Redacted sender "sfzhi@xxxxxxxxx" for DMARC) 写道:
>>> 
>>> Back to the point, which is my original email. Please kindly ignore
>>> everything written after that as irrelevant. However, to avoid any
>>> further meaningless arguments, here is a modified version of the example
>>> code, which does not change anything with respect to the segmentation
>>> fault:
>>> 
>>> #include <lua.h>
>>> #include <lualib.h>
>>> #include <lauxlib.h>
>>> #include <stdio.h>
>>> 
>>> int main()
>>> {
>>>  lua_State *lua = luaL_newstate();
>>>  luaL_openlibs(lua);
>>>  lua_State *lua2 = lua_newthread(lua);
>>>  luaL_loadstring(lua2, "coroutine.yield()");
>>>  int res = lua_resume(lua2, 0);
>>>  printf("res=%d, top=%d\n", res, lua_gettop(lua2));
>>>  lua_pushliteral(lua2, "test");
>>>  lua_error(lua2);
>>>  return 0;
>>> }
>> 
>> Now there is already a main thread lua and a slave thread lua2. The core
>> of this problem is trying to throw an error on an yielded thread lua2,
>> whose behavior is *undefined*. No code can be executed on an yielded
>> thread, so how can there be an error thrown on it? Did you try throwing an
>> error on lua(which is not yielded) instead of lua2?
>> 
>> There is no way to throw an error  on an yielded thread with pure Lua
>> code. At least I didn't find one.
> 
>  Sergei is not trying to do that.  What he is trying to report is a
> condition that PUC Lua 5.1 handles:
> 
> [spc]lucy:/tmp>gcc -o s s.c -llua -lm -ldl
> [spc]lucy:/tmp>./s
> res=1, top=0
> PANIC: unprotected error in call to Lua API (test)
> 
> That LuaJIT does not:
> 
> [spc]lucy:/tmp>gcc -o s s.c -lluajit-5.1 -lm -ldl
> [spc]lucy:/tmp>./s
> res=1, top=0
> Segmentation fault (core dumped)
> 
>  -spc
> 
> 

Other related posts: