2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-01 06:45:38 +00:00

Catch PermissionError when trying to write a profile

... and re-raise it as AppArmorException so that only the actual error
(without a backtrace) gets displayed.

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/282
This commit is contained in:
Christian Boltz
2022-11-14 22:50:27 +01:00
parent 9107a0d891
commit d0ec2acaf2

View File

@@ -2277,6 +2277,7 @@ def write_profile(profile, is_attachment=False):
serialize_options = {'METADATA': True, 'is_attachment': is_attachment}
profile_string = serialize_profile(split_to_merged(aa), profile, serialize_options)
try:
with NamedTemporaryFile('w', suffix='~', delete=False, dir=profile_dir) as newprof:
if os.path.exists(prof_filename):
shutil.copymode(prof_filename, newprof.name)
@@ -2285,6 +2286,9 @@ def write_profile(profile, is_attachment=False):
# os.chmod(newprof.name, permission_600)
pass
newprof.write(profile_string)
except PermissionError as e:
raise AppArmorException(e)
os.rename(newprof.name, prof_filename)
if profile in changed: