Skip to content

Commit

Permalink
reset_machine_id: ask for forgiveness, not permission
Browse files Browse the repository at this point in the history
Avoid TOCTOU by always deleting and handling the FileNotFoundError
  • Loading branch information
fsateler committed Mar 1, 2017
1 parent 122d787 commit 8c91ff1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mkosi
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,11 @@ def reset_machine_id(args, workspace, run_build_script):
os.unlink(machine_id)
open(machine_id, "w+b").close()
dbus_machine_id = os.path.join(workspace, 'root', 'var/lib/dbus/machine-id')
if os.path.exists(dbus_machine_id):
try:
os.unlink(dbus_machine_id)
except FileNotFoundError:
pass
else:
os.symlink('../../../etc/machine-id', dbus_machine_id)

def set_root_password(args, workspace, run_build_script):
Expand Down

0 comments on commit 8c91ff1

Please sign in to comment.