From 1ba708d1f16e74e037b89d6cb9a55efc84b5ac1c Mon Sep 17 00:00:00 2001 From: curried Date: Wed, 10 Sep 2025 11:18:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增对opendir()返回值的判空逻辑,避免目录打开失败时程序崩溃,记录errno fix pPtable_ null point problem Ptable::DeletePartitionTmpFile()改为静态函数,便于任何时候执行临时分区清理工作,并避免空指针访问 check UpgradePkg buffer fix missing lock for pkgStreams_ Signed-off-by: curried --- services/package/pkg_manager/pkg_managerImpl.cpp | 1 + services/ptable_parse/ptable.h | 2 +- services/ptable_parse/ptable_manager.cpp | 8 ++++---- utils/utils_fs.cpp | 7 ++++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/services/package/pkg_manager/pkg_managerImpl.cpp b/services/package/pkg_manager/pkg_managerImpl.cpp index 04f197a6..ac4e08ab 100644 --- a/services/package/pkg_manager/pkg_managerImpl.cpp +++ b/services/package/pkg_manager/pkg_managerImpl.cpp @@ -548,6 +548,7 @@ PkgEntryPtr PkgManagerImpl::GetPkgEntry(const std::string &path) PkgManager::StreamPtr PkgManagerImpl::GetPkgFileStream(const std::string &fileName) { + std::lock_guard lock(mapLock_); auto iter = pkgStreams_.find(fileName); if (iter != pkgStreams_.end()) { return (*iter).second; diff --git a/services/ptable_parse/ptable.h b/services/ptable_parse/ptable.h index 654e10d8..fb29fe59 100644 --- a/services/ptable_parse/ptable.h +++ b/services/ptable_parse/ptable.h @@ -82,7 +82,7 @@ public: std::vector& GetPtablePartitionInfoInstance(); bool LoadPtnInfo(const std::vector& ptnInfo); bool ReadPartitionFileToBuffer(uint8_t *ptbImgBuffer, uint32_t &imgBufSize); - void DeletePartitionTmpFile(); + static void DeletePartitionTmpFile(); virtual bool WritePartitionBufToFile(uint8_t *ptbImgBuffer, const uint32_t imgBufSize); virtual bool ParsePartitionFromBuffer(uint8_t *ptbImgBuffer, const uint32_t imgBufSize) = 0; diff --git a/services/ptable_parse/ptable_manager.cpp b/services/ptable_parse/ptable_manager.cpp index 2534f183..438db6ad 100644 --- a/services/ptable_parse/ptable_manager.cpp +++ b/services/ptable_parse/ptable_manager.cpp @@ -334,24 +334,24 @@ bool PtableManager::WritePtableWithFile() { if (pPtable_ == nullptr) { LOG(ERROR) << "pPtable_ is nullptr"; - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); return true; } if (!LoadPartitionInfoWithFile()) { LOG(ERROR) << "load partition info with file fail"; - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); return true; } #ifndef UPDATER_UT if (!pPtable_->WritePartitionTable()) { LOG(ERROR) << "Write ptable to device failed! Please load ptable first!"; - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); return false; } #endif - pPtable_->DeletePartitionTmpFile(); + Ptable::DeletePartitionTmpFile(); LOG(INFO) << "write patble with file success"; return true; } diff --git a/utils/utils_fs.cpp b/utils/utils_fs.cpp index d14497f3..9a730c03 100644 --- a/utils/utils_fs.cpp +++ b/utils/utils_fs.cpp @@ -77,7 +77,11 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector return -1; } DIR *dirp = opendir(path.c_str()); - struct dirent *dp; + if (dirp == nullptr) { + LOG(ERROR) << "Failed to opendir errno=" << errno; + return -1; + } + struct dirent *dp = nullptr; int64_t totalSize = 0; while ((dp = readdir(dirp)) != nullptr) { std::string fileName = path + "/" + dp->d_name; @@ -95,6 +99,7 @@ int64_t GetFilesFromDirectory(const std::string &path, std::vector } } closedir(dirp); + dirp = nullptr; return totalSize; } -- Gitee