diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2021-02-10 11:27:29 -0800 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2021-02-10 11:58:27 -0800 |
commit | b49cb5eceaf426644da85ff9ab250d9c9aa7c510 (patch) | |
tree | 604d7c5ff462e48180467b93674c0f848930a074 /cmds/idmap2/idmap2d/Idmap2Service.cpp | |
parent | 17e971d53101bf5cc4223beb16c79820b3ad5200 (diff) |
Always delete old idmap in createIdmap
If the target package updates its policies, and the overlay fails to
successfully overlay any resources, the overlay should no longer work
anymore. By deleting the old idmap file at the beginning of
Idmap2Service::createIdmap, the overlay state will change to
STATE_NO_IDMAP if the new idmap cannot be successfully generated.
Bug: 173032050
Test: manual
Change-Id: I1915e65feeb801d8602c12cc7df0f90da4c9b5c5
Diffstat (limited to 'cmds/idmap2/idmap2d/Idmap2Service.cpp')
-rw-r--r-- | cmds/idmap2/idmap2d/Idmap2Service.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp index 312f4acbda9f..05336baf9217 100644 --- a/cmds/idmap2/idmap2d/Idmap2Service.cpp +++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp @@ -161,6 +161,12 @@ Status Idmap2Service::createIdmap(const std::string& target_path, const std::str idmap_path.c_str(), uid)); } + // idmap files are mapped with mmap in libandroidfw. Deleting and recreating the idmap guarantees + // that existing memory maps will continue to be valid and unaffected. The file must be deleted + // before attempting to create the idmap, so that if idmap creation fails, the overlay will no + // longer be usable. + unlink(idmap_path.c_str()); + const auto target = GetTargetContainer(target_path); if (!target) { return error("failed to load target '%s'" + target_path); @@ -177,10 +183,6 @@ Status Idmap2Service::createIdmap(const std::string& target_path, const std::str return error(idmap.GetErrorMessage()); } - // idmap files are mapped with mmap in libandroidfw. Deleting and recreating the idmap guarantees - // that existing memory maps will continue to be valid and unaffected. - unlink(idmap_path.c_str()); - umask(kIdmapFilePermissionMask); std::ofstream fout(idmap_path); if (fout.fail()) { |