Skip to content

Commit fc9747e

Browse files
committedNov 8, 2017
Make use of safe file writing in auth handler (fixes #6576)
1 parent b692454 commit fc9747e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed
 

‎builtin/game/auth.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ local function save_auth_file()
4242
assert(type(stuff.privileges) == "table")
4343
assert(stuff.last_login == nil or type(stuff.last_login) == "number")
4444
end
45-
local file, errmsg = io.open(core.auth_file_path, 'w+b')
46-
if not file then
47-
error(core.auth_file_path.." could not be opened for writing: "..errmsg)
48-
end
45+
local content = ""
4946
for name, stuff in pairs(core.auth_table) do
5047
local priv_string = core.privs_to_string(stuff.privileges)
5148
local parts = {name, stuff.password, priv_string, stuff.last_login or ""}
52-
file:write(table.concat(parts, ":").."\n")
49+
content = content .. table.concat(parts, ":") .. "\n"
50+
end
51+
if not core.safe_file_write(core.auth_file_path, content) then
52+
error(core.auth_file_path.." could not be written to")
5353
end
54-
io.close(file)
5554
end
5655

5756
read_auth_file()

0 commit comments

Comments
 (0)
Please sign in to comment.