From 915f986e3d4a9c9a3d5a131770abfafa1e3198d7 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 27 Jan 2022 22:23:14 +0100 Subject: [PATCH] Builtin: Sanity-check /time inputs This enforces the documented bounds for the /time command. --- builtin/game/chat.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index 50665154d..fc0b861ff 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -933,12 +933,11 @@ core.register_chatcommand("time", { end local hour, minute = param:match("^(%d+):(%d+)$") if not hour then - local new_time = tonumber(param) - if not new_time then - return false, "Invalid time." + local new_time = tonumber(param) or -1 + if new_time ~= new_time or new_time < 0 or new_time > 24000 then + return false, "Invalid time (must be between 0 and 24000)." end - -- Backward compatibility. - core.set_timeofday((new_time % 24000) / 24000) + core.set_timeofday(new_time / 24000) core.log("action", name .. " sets time to " .. new_time) return true, "Time of day changed." end