1
0

safer os.chmod for wallet files and config: set perms before write

Set unix file permissions first, before writing data.
This commit is contained in:
SomberNight
2024-04-08 13:55:52 +00:00
parent 6d37e464f3
commit f495511886
3 changed files with 10 additions and 10 deletions

View File

@@ -421,8 +421,8 @@ class SimpleConfig(Logger):
s = json.dumps(self.user_config, indent=4, sort_keys=True)
try:
with open(path, "w", encoding='utf-8') as f:
os_chmod(path, stat.S_IREAD | stat.S_IWRITE) # set restrictive perms *before* we write data
f.write(s)
os_chmod(path, stat.S_IREAD | stat.S_IWRITE)
except OSError:
# datadir probably deleted while running... e.g. portable exe running on ejected USB drive
# (in which case it is typically either FileNotFoundError or PermissionError,