From 10ce37d887ff5272cc6574fb4f31d48535aa793d Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Sun, 22 Aug 2021 04:19:06 +0200 Subject: [PATCH] Fix server crash by client leaving after joining When a player joins and immediately leaves the game before a function is called by minetest.after() in mods/PLAYER/wieldview/init.lua, it gets an invalidated player object. This results in the player methods returning nil (since Minetest 5.2); perhaps surprisingly, the player is not nil. Not checking that the result of player:get_pos() is not nil could lead to a server crash if a client crashed when joining. It has been reported that a syntax error in a client side mod was enough to trigger that. --- mods/PLAYER/wieldview/init.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mods/PLAYER/wieldview/init.lua b/mods/PLAYER/wieldview/init.lua index 4514ca5e..17c38e20 100644 --- a/mods/PLAYER/wieldview/init.lua +++ b/mods/PLAYER/wieldview/init.lua @@ -70,8 +70,22 @@ minetest.register_on_joinplayer(function(player) local name = player:get_player_name() wieldview.wielded_item[name] = "" minetest.after(0, function(player) + -- When a player joins and immediately leaves the game + -- before this function is called by minetest.after(), + -- the player object is invalidated. This results in + -- its methods returning nil (since Minetest 5.2); + -- perhaps surprisingly, the player is not nil. + -- + -- Not checking that the position is not nil can lead + -- to a server crash if a client crashes while it is + -- joining. It has been reported that a syntax error + -- in a client side mod was enough to trigger that. + local pos = player:get_pos() + if pos == nil then + return + end wieldview:update_wielded_item(player) - local itementity = minetest.add_entity(player:get_pos(), "wieldview:wieldnode") + local itementity = minetest.add_entity(pos, "wieldview:wieldnode") itementity:set_attach(player, "Hand_Right", vector.new(0, 0, 0), vector.new(15, 45, 0)) itementity:get_luaentity().wielder = name end, player)