Make use of safe file writing in auth handler (fixes #6576)
authorsfan5 <sfan5@live.de>
Tue, 7 Nov 2017 10:47:28 +0000 (11:47 +0100)
committerSmallJoker <mk939@ymail.com>
Sun, 3 Jun 2018 15:32:00 +0000 (17:32 +0200)
builtin/game/auth.lua

index 8cb4ebf57dedbfb57c1e37c3ddaa3df9a6409804..74eb6ae88f71665166591ca1d75a23c92f2fd843 100644 (file)
@@ -67,16 +67,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()