From 5612034ef9bd61e01450f517ab9cca0e5312a0f5 Mon Sep 17 00:00:00 2001 From: g00613291 Date: Sat, 30 Nov 2024 19:18:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=20crash=20when=20bundleName=20is=20invalid?= =?UTF-8?q?=20=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: g00613291 --- services/backup_sa/src/module_external/bms_adapter.cpp | 4 ++++ utils/src/b_jsonutil/b_jsonutil.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 33d21e327..7b79c511f 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -119,6 +119,10 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto HILOGI("Start, bundleNames size:%{public}zu", bundleNames.size()); for (auto const &bundleName : bundleNames) { HILOGI("Begin Get bundleName:%{public}s", bundleName.c_str()); + if (bundleName.empty()) { + HILOGE("BundleName is invalid"); + continue; + } if (SAUtils::IsSABundleName(bundleName)) { GetBundleInfoForSA(bundleName, bundleInfos); continue; diff --git a/utils/src/b_jsonutil/b_jsonutil.cpp b/utils/src/b_jsonutil/b_jsonutil.cpp index fcdce2a6d..c420dc136 100644 --- a/utils/src/b_jsonutil/b_jsonutil.cpp +++ b/utils/src/b_jsonutil/b_jsonutil.cpp @@ -70,6 +70,10 @@ std::map> BJsonUtil::Build HILOGI("Start BuildBundleInfos"); for (size_t i = 0; i < bundleNames.size(); i++) { std::string bundleName = bundleNames[i]; + if (bundleName.empty()) { + HILOGE("BundleName is invalid"); + continue; + } std::vector bundleDetailInfos; size_t pos = bundleName.find(BUNDLE_INDEX_SPLICE); if (pos == 0 || pos == (bundleName.size() - 1)) { @@ -84,10 +88,9 @@ std::map> BJsonUtil::Build bundleNamesOnly.emplace_back(bundleName); } else { std::string bundleNameSplit = bundleName.substr(0, pos); - std::string indexSplit = ""; if (to_string(bundleName.back()) != BUNDLE_INDEX_SPLICE) { - indexSplit = bundleName.substr(pos + 1); - int index = std::stoi(indexSplit); + std::string indexSplit = bundleName.substr(pos + 1); + int index = std::atoi(indexSplit.c_str()); bundleIndex = index; } else { bundleIndex = BUNDLE_INDEX_DEFAULT_VAL; -- Gitee