diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 33d21e327758bbcf8ebc95afa717942fbbe84900..7b79c511f4e57e9c67d34f7b5db75845e4d185d8 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 fcdce2a6d028357c851337441e9d82cb11533332..c420dc13668233a51a4e7e08196d3c36f5e9fab5 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;