Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving luac from position results in server crash #566

Closed
Bastrabun opened this issue Jun 2, 2021 · 3 comments
Closed

Moving luac from position results in server crash #566

Bastrabun opened this issue Jun 2, 2021 · 3 comments

Comments

@Bastrabun
Copy link

Bastrabun commented Jun 2, 2021

Repro:

  1. Place a luacontroller
  2. Add this code:
interrupt(0.1,'')
  1. Use Worldedit to remove the luacontroller

Another Repro:

  1. Place luacontroller
  2. Place a digilines piston next to it
  3. Place a second luacontroller that would be moved by the extending piston
  4. Add this code to the first luacontroller
digiline_send('',"extend")
interrupt(0.1,'')

This is what happens:

2021-06-02 07:39:09: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod 'mesecons_luacontroller' in callback environment_Step(): .../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:472: bad argument #1 to 'pairs' (table expected, got nil)
2021-06-02 07:39:09: ERROR[Main]: stack traceback:
2021-06-02 07:39:09: ERROR[Main]: 	[C]: in function 'pairs'
2021-06-02 07:39:09: ERROR[Main]: 	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:472: in function 'create_environment'
2021-06-02 07:39:09: ERROR[Main]: 	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:627: in function 'run_inner'
2021-06-02 07:39:09: ERROR[Main]: 	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:686: in function 'run'
2021-06-02 07:39:09: ERROR[Main]: 	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:753: in function 'action'
2021-06-02 07:39:09: ERROR[Main]: 	/home/mtlive1/.minetest/mods/digilines/internal.lua:106: in function 'transmit'
2021-06-02 07:39:09: ERROR[Main]: 	/home/mtlive1/.minetest/mods/digilines/init.lua:53: in function 'receptor_send'
2021-06-02 07:39:09: ERROR[Main]: 	.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:724: in function <.../.minetest/mods/mesecons/mesecons_luacontroller/init.lua:718>
2021-06-02 07:39:09: ERROR[Main]: 	...mtlive1/.minetest/mods/mesecons/mesecons/actionqueue.lua:137: in function 'old_execute'
2021-06-02 07:39:09: ERROR[Main]: 	/home/mtlive1/.minetest/mods/mesecons_debug/overrides.lua:7: in function 'execute'
2021-06-02 07:39:09: ERROR[Main]: 	...mtlive1/.minetest/mods/mesecons/mesecons/actionqueue.lua:111: in function <...mtlive1/.minetest/mods/mesecons/mesecons/actionqueue.lua:73>
2021-06-02 07:39:09: ERROR[Main]: 	...ve1/5.4.1/Minetest_live/bin/../builtin/game/register.lua:422: in function <...ve1/5.4.1/Minetest_live/bin/../builtin/game/register.lua:406>
2021-06-02 07:39:09: ERROR[Main]: stack traceback:

This is how it can be fixed:

 local function run(pos, event)

+       if string.sub(core.get_node(pos).name,0,36) ~= "mesecons_luacontroller:luacontroller" then
+               return false, "Luac does not exist anymore"
+       end
        local meta = minetest.get_meta(pos)
        local code = meta:get_string("code")
        local ok, errmsg = run_inner(pos, code, event)

Thanks to Test_User who discovered it and whosit who debugged it and found a solution.

For my reference: #610

@numberZero
Copy link
Contributor

Doesn’t sound like our bug but as defensive coding, the workaround can be accepted. I’d also check for the controller ID, to not run the code on a wrong controller should there be one.

@fluxionary
Copy link
Contributor

it seems that the crash here has been mitigated by a nil check since the bug was reported:

code, as it was when this was reported:

local vports = minetest.registered_nodes[minetest.get_node(pos).name].virtual_portstates
local vports_copy = {}
for k, v in pairs(vports) do vports_copy[k] = v end

code, as it is now:

local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def then return end
local vports = node_def.virtual_portstates
if not vports then return end
local vports_copy = {}
for k, v in pairs(vports) do vports_copy[k] = v end

however i haven't tested whether there's still a crash if a luac is WE'ed or MVPS'ed, there might be other problems.

@numberZero
Copy link
Contributor

numberZero commented May 7, 2023

it seems that the crash here has been mitigated by a nil check since the bug was reported:

@fluxionary thanks for noticing! Tested with Mesecons piston and Digistuff piston. No crash or other problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants