1
0
mirror of https://github.com/minetest/minetest_game.git synced 2025-06-28 04:40:22 +02:00

Validate & sanitize formspec fields (#3022)

This commit is contained in:
Lars Müller
2023-04-08 18:13:45 +02:00
committed by GitHub
parent 4c6e19968a
commit 833ed77620
4 changed files with 16 additions and 9 deletions

View File

@ -148,7 +148,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
if fields.close then
if fields.quit then
book_writers[player_name] = nil
end
@ -179,6 +179,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
data.description = S("\"@1\" by @2", short_title, data.owner)
data.text = fields.text:sub(1, max_text_size)
data.text = data.text:gsub("\r\n", "\n"):gsub("\r", "\n")
data.text = data.text:gsub("[%z\1-\8\11-\31\127]", "") -- strip naughty control characters (keeps \t and \n)
data.page = 1
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)

View File

@ -2597,12 +2597,12 @@ local function register_sign(material, desc, def)
if not text then
return
end
if string.len(text) > 512 then
if #text > 512 then
minetest.chat_send_player(player_name, S("Text too long"))
return
end
default.log_player_action(sender, "wrote \"" .. text ..
"\" to the sign at", pos)
text = text:gsub("[%z-\8\11-\31\127]", "") -- strip naughty control characters (keeps \t and \n)
default.log_player_action(sender, ("wrote %q to the sign at"):format(text), pos)
local meta = minetest.get_meta(pos)
meta:set_string("text", text)