aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-11-07 11:47:28 +0100
committersfan5 <sfan5@live.de>2017-11-08 16:14:05 +0100
commitfc9747eb4b7f75e59a28957bc50f7a78256b3d66 (patch)
treee94c954e2ba783e4c881ab07848435adcde8bf41
parentb692454f70cb661a8ce733a4bcbbadcb5edd0049 (diff)
downloadminetest-fc9747eb4b7f75e59a28957bc50f7a78256b3d66.tar.gz
minetest-fc9747eb4b7f75e59a28957bc50f7a78256b3d66.tar.bz2
minetest-fc9747eb4b7f75e59a28957bc50f7a78256b3d66.zip
Make use of safe file writing in auth handler (fixes #6576)
-rw-r--r--builtin/game/auth.lua11
1 files changed, 5 insertions, 6 deletions
diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua
index bf5bd19a8..3a478111c 100644
--- a/builtin/game/auth.lua
+++ b/builtin/game/auth.lua
@@ -42,16 +42,15 @@ local function save_auth_file()
assert(type(stuff.privileges) == "table")
assert(stuff.last_login == nil or type(stuff.last_login) == "number")
end
- local file, errmsg = io.open(core.auth_file_path, 'w+b')
- if not file then
- error(core.auth_file_path.." could not be opened for writing: "..errmsg)
- end
+ local content = ""
for name, stuff in pairs(core.auth_table) do
local priv_string = core.privs_to_string(stuff.privileges)
local parts = {name, stuff.password, priv_string, stuff.last_login or ""}
- file:write(table.concat(parts, ":").."\n")
+ content = content .. table.concat(parts, ":") .. "\n"
+ end
+ if not core.safe_file_write(core.auth_file_path, content) then
+ error(core.auth_file_path.." could not be written to")
end
- io.close(file)
end
read_auth_file()