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

mesecons/mesecons_detector/init.lua:70: bad argument #2 to 'set_string' (string expected, got table) #691

Closed
Bastrabun opened this issue Nov 29, 2024 · 3 comments

Comments

@Bastrabun
Copy link

Bastrabun commented Nov 29, 2024

Upstream issue mesecons:

Repro:

Have mesecons, digilines

  1. Place mesecons_luacontroller:luacontroller
  2. Place mesecons_detector:object_detector
  3. Add channel "kaputt" to object_detector
  4. Add code to luacontroller: digiline_send("kaputt",{})
  5. Press Execute

Crash

AsyncErr: Lua: Runtime error from mod 'mesecons' in callback environment_Step(): ...est-temp/bin/../mods/mesecons/mesecons_detector/init.lua:70: bad argument #2 to 'set_string' (string expected, got table)
stack traceback:
	[C]: in function 'set_string'
	...est-temp/bin/../mods/mesecons/mesecons_detector/init.lua:70: in function 'action'
	.../5.10.0/minetest-temp/bin/../mods/digilines/internal.lua:106: in function 'transmit'
	...test/5.10.0/minetest-temp/bin/../mods/digilines/init.lua:60: in function 'receptor_send'
	...emp/bin/../mods/mesecons/mesecons_luacontroller/init.lua:752: in function <...emp/bin/../mods/mesecons/mesecons_luacontroller/init.lua:746>
	...etest-temp/bin/../mods/mesecons/mesecons/actionqueue.lua:131: in function 'execute'
	...etest-temp/bin/../mods/mesecons/mesecons/actionqueue.lua:121: in function <...etest-temp/bin/../mods/mesecons/mesecons/actionqueue.lua:76>
	.../5.10.0/minetest-temp/bin/../builtin/common/register.lua:26: in function <.../5.10.0/minetest-temp/bin/../builtin/common/register.lua:12>

This doesn't happen in 5.8.0, only in 5.9.1 and 5.10.0 and 5.11.0-dev

The difference is in handling of incorrect arguments in case of meta:set_string("key", {}) - it silently unsets the key on 5.8 and errors on 5.9+

Please add a type check

Similar minetest-mods/MoreMesecons#38

For my reference 7743

@SmallJoker
Copy link
Member

Does this fix your issue as intended? I took digistuff/gpu.lua as a reference where the type is checked in the same way.

diff --git a/mesecons_detector/init.lua b/mesecons_detector/init.lua
index a8d0300..2653174 100644
--- a/mesecons_detector/init.lua
+++ b/mesecons_detector/init.lua
@@ -66,7 +66,8 @@ local object_detector_digiline = {
        effector = {
                action = function(pos, _, channel, msg)
                        local meta = minetest.get_meta(pos)
-                       if channel == meta:get_string("digiline_channel") then
+                       if channel == meta:get_string("digiline_channel") and
+                                       (type(msg) == "string" or type(msg) == "number") then
                                meta:set_string("scanname", msg)
                                object_detector_make_formspec(pos)
                        end

@cheapie
Copy link
Contributor

cheapie commented Dec 5, 2024

That looks like it would work (haven't tried it yet) but it should probably only check for strings as numbers aren't valid values.

@SmallJoker
Copy link
Member

5c82089

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

No branches or pull requests

3 participants