From 1c8d814cea0a794e3fac8c9ab5ab7d92ef048bbe Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Mon, 9 Nov 2020 22:15:16 -0800 Subject: [PATCH] fs_mgr: fix potential uses of nullptr Clang's static analyzer flagged the following potential null pointer dereferences. Looks like a transitive caller of this function has ``` if (change) *change = foo; ``` ...and no nullness checks between that and these unconditional assignments to `*change`. > system/core/fs_mgr/fs_mgr_overlayfs.cpp:1100:13: warning: Dereference of null pointer (loaded from variable 'change') [clang-analyzer-core.NullDereference] > system/core/fs_mgr/fs_mgr_overlayfs.cpp:1167:17: warning: Dereference of null pointer (loaded from variable 'change') [clang-analyzer-core.NullDereference] Bug: None Test: TreeHugger Change-Id: I656e3b0f56b18ec3ca3d1db773feb81adf163122 --- fs_mgr/fs_mgr_overlayfs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index a7704de69..01d7914ae 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -1045,7 +1045,7 @@ static bool CreateDynamicScratch(std::string* scratch_device, bool* partition_ex static bool CreateScratchOnData(std::string* scratch_device, bool* partition_exists, bool* change) { *partition_exists = false; - *change = false; + if (change) *change = false; auto images = IImageManager::Open("remount", 10s); if (!images) { @@ -1065,7 +1065,7 @@ static bool CreateScratchOnData(std::string* scratch_device, bool* partition_exi return false; } - *change = true; + if (change) *change = true; // Note: calling RemoveDisabledImages here ensures that we do not race with // clean_scratch_files and accidentally try to map an image that will be