Skip to content

Commit

Permalink
Make use of safe file writing in auth handler (fixes #6576)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Nov 8, 2017
1 parent b692454 commit fc9747e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions builtin/game/auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit fc9747e

Please sign in to comment.