Skip to content

Commit

Permalink
Builtin: Sanity-check /time inputs (minetest#11993)
Browse files Browse the repository at this point in the history
This enforces the documented bounds for the /time command.
  • Loading branch information
SmallJoker committed Jan 27, 2022
1 parent fe0b2d0 commit 47735c2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions builtin/game/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47735c2

Please sign in to comment.