]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Builtin: Sanity-check /time inputs (#11993)
authorSmallJoker <SmallJoker@users.noreply.github.com>
Thu, 27 Jan 2022 21:23:14 +0000 (22:23 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Jan 2022 21:23:14 +0000 (22:23 +0100)
This enforces the documented bounds for the /time command.

builtin/game/chat.lua

index 99296f78247612300c8f3b8984b444577ea14709..0f5739d5c0b28efb8f4d2676cbfd6d7c307b6bc2 100644 (file)
@@ -1034,12 +1034,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, S("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, S("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, S("Time of day changed.")
                end