lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Many thanks for Sergey Zakharchenko, Roberto Ierusalimschy.

After applying the suggested patch, it was confirmed that the crash no longer occurred.

by the way, I have one question, is the patching direction going toward not giving the following error message?


stdin:1: bad argument #1 to 'rep' (string expected, got no value)
stack traceback:
    [C]: in function 'string.rep'
    stdin:1: in main chunk
    [C]: in ?

2021. 12. 1. 오전 3:11에 Roberto Ierusalimschy 이(가) 쓴 글:
Hi, I found an interesting SEGV crash on Lua interpreter.

Lua .5.4.4, commit hash ad3942adba574c9d008c99ce2785a5af19d146bf

local function v(a, b, c, ...)
return os.exit(0, true)

local function a()
return h()

local e <close> = setmetatable({}, {__close = a})

Many thanks for the feedback.

The issue here is that, when closing the state, Lua assumes its stack
is going away, so it could close 'e' using all the stack after it.
However, the call to 'v' is still pending, and when the error tries
to create a traceback, the information about the call to 'v' has
been messed up by the closing of 'e'.

The fix seems simple:

--- a/lstate.c
+++ b/lstate.c
@@ -271,6 +271,7 @@ static void close_state (lua_State *L) {
    if (!completestate(g))  /* closing a partially built state? */
      luaC_freeallobjects(L);  /* just collect its objects */
    else {  /* closing a fully built state */
+    L->ci = &L->base_ci;  /* unwind CallInfo list */
      luaD_closeprotected(L, 1, LUA_OK);  /* close all upvalues */
      luaC_freeallobjects(L);  /* collect all objects */

-- Roberto