diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index c434ef30523130f0fde763cb270e74951d7d1c94..b9314012850bd4a2159b56882dab380f6fd9f37f 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1912,7 +1912,6 @@ std::function BackupExtExtension::HandleTaskBa void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point &startTime, int &fdSendNum) { - HILOGI("WaitToSendFd Begin"); std::unique_lock lock(startSendMutex_); startSendFdRateCon_.wait(lock, [this] { return sendRate_ > 0; }); if (fdSendNum >= sendRate_) { @@ -1930,7 +1929,6 @@ void BackupExtExtension::WaitToSendFd(std::chrono::system_clock::time_point &sta fdSendNum = 0; startTime = std::chrono::system_clock::now(); } - HILOGI("WaitToSendFd End"); } void BackupExtExtension::RefreshTimeInfo(std::chrono::system_clock::time_point &startTime, int &fdSendNum) diff --git a/interfaces/kits/cj/src/file_fileuri_ffi.cpp b/interfaces/kits/cj/src/file_fileuri_ffi.cpp index 58d8d138be88c4333ec6ab430f6596ac6915c293..7a2031b92560345121f6dbf99195b9140acf2baf 100644 --- a/interfaces/kits/cj/src/file_fileuri_ffi.cpp +++ b/interfaces/kits/cj/src/file_fileuri_ffi.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "b_resources/b_constants.h" #include "file_fileuri_ffi.h" #include "file_uri.h" #include "macro.h" @@ -33,6 +34,10 @@ char* MallocCString(const std::string& origin) if (origin.empty()) { return nullptr; } + if (origin.length() > BConstants::PARAM_STRING_MAX_MEMORY) { + LOGE("The param origin is too big"); + return nullptr; + } auto length = origin.length() + 1; char* res = static_cast(malloc(sizeof(char) * length)); if (res == nullptr) { diff --git a/interfaces/kits/js/backup/general_callbacks.cpp b/interfaces/kits/js/backup/general_callbacks.cpp index ed667125e06ea9644249cea205d4eb68064e40e3..05fcd67862ccb580d54ef83d42a0d73df9f2c95c 100644 --- a/interfaces/kits/js/backup/general_callbacks.cpp +++ b/interfaces/kits/js/backup/general_callbacks.cpp @@ -66,6 +66,9 @@ BackupRestoreCallback::~BackupRestoreCallback() BackupRestoreCallback::operator bool() const { + if (ctx_ == nullptr) { + return false; + } return bool(ctx_->cb_); } diff --git a/interfaces/kits/ndk/fileuri/src/oh_file_uri.cpp b/interfaces/kits/ndk/fileuri/src/oh_file_uri.cpp index b6ffc8843e3ef751f9efa2f2ab9dec15c96e76cd..d2361fdc300ccec3d1f4ca92a6f31e48defabb0a 100644 --- a/interfaces/kits/ndk/fileuri/src/oh_file_uri.cpp +++ b/interfaces/kits/ndk/fileuri/src/oh_file_uri.cpp @@ -16,6 +16,7 @@ #include +#include "b_resources/b_constants.h" #include "file_uri.h" #include "log.h" #include "securec.h" @@ -27,6 +28,10 @@ static FileManagement_ErrCode GetValue(std::string_view resultStr, char **result if (count == 0) { return ERR_UNKNOWN; } + if (count > BConstants::PARAM_STRING_MAX_MEMORY) { + LOGE("The param origin is too big"); + return ERR_UNKNOWN; + } *result = static_cast(malloc(sizeof(char) * (count + 1))); if (*result == nullptr) { LOGE("malloc is feiled!"); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 1e34fc20a16379b36cb9c59d94e3ea9baa738833..0645a1eefb351e66cf894183361dbdde4c4130b2 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -591,7 +591,9 @@ ErrCode Service::PublishFile(const BFileInfo &fileInfo) return EPERM; } auto backUpConnection = session_->GetExtConnection(fileInfo.owner); - + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -664,6 +666,9 @@ ErrCode Service::AppDone(ErrCode errCode) string callerName = VerifyCallerAndGetCallerName(); if (session_->OnBundleFileReady(callerName)) { auto backUpConnection = session_->GetExtConnection(callerName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is null"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -757,6 +762,9 @@ void Service::NotifyCloneBundleFinish(std::string bundleName) { if (session_->OnBundleFileReady(bundleName)) { auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is null"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -805,7 +813,9 @@ ErrCode Service::LaunchBackupExtension(const BundleName &bundleName) want.SetParam(BConstants::EXTENSION_BACKUP_EXT_INFO_PARA, bundleExtInfo); auto backUpConnection = session_->GetExtConnection(bundleName); - + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is null"); + } ErrCode ret = backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); return ret; } catch (const BError &e) { @@ -852,6 +862,9 @@ ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName) auto action = session_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::RUNNING) { auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is null"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -892,6 +905,10 @@ void Service::OnBackupExtensionDied(const string &&bundleName) // 重新连接清理缓存 HILOGE("Clear backup extension data, bundleName: %{public}s", bundleName.data()); auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + HILOGE("Backup <%{public}s> Extension Process Died, backUpConnection is null", callName.c_str()); + return; + } auto callConnected = [ptr {wptr(this)}](const string &&bundleName) { HILOGE("OnBackupExtensionDied callConnected <%{public}s>", bundleName.c_str()); auto thisPtr = ptr.promote(); @@ -922,6 +939,10 @@ void Service::ExtConnectDied(const string &callName) /* Clear Timer */ session_->BundleExtTimerStop(callName); auto backUpConnection = session_->GetExtConnection(callName); + if (backUpConnection == nullptr) { + HILOGW("Begin, bundleName: %{public}s, backUpConnection is null", callName.c_str()); + return; + } if (backUpConnection->IsExtAbilityConnected()) { backUpConnection->DisconnectBackupExtAbility(); } @@ -951,6 +972,9 @@ void Service::ExtStart(const string &bundleName) } IServiceReverse::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is null"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -977,7 +1001,7 @@ void Service::ExtStart(const string &bundleName) } return; } catch (...) { - HILOGI("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); + HILOGE("Unexpected exception, bundleName: %{public}s", bundleName.c_str()); ClearSessionAndSchedInfo(bundleName); NoticeClientFinish(bundleName, BError(BError::Codes::SA_INVAL_ARG)); return; @@ -987,7 +1011,7 @@ void Service::ExtStart(const string &bundleName) int Service::Dump(int fd, const vector &args) { if (fd < 0) { - HILOGI("HiDumper handle invalid"); + HILOGE("HiDumper handle invalid"); return -1; } @@ -1437,9 +1461,14 @@ ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool return BError(BError::Codes::SA_INVAL_ARG); } auto backupConnection = session_->GetExtConnection(bundleName); + if (backupConnection == nullptr) { + HILOGE("The backupConnection is null"); + return BError(BError::Codes::SA_INVAL_ARG); + } auto proxy = backupConnection->GetBackupExtProxy(); if (!proxy) { - throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + HILOGE("The extension proxy is null"); + return BError(BError::Codes::SA_INVAL_ARG); } auto ret = proxy->UpdateFdSendRate(bundleName, sendRate); if (ret != NO_ERROR) { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 0d8cc248ea9292551228d41590458b3d4e91c66c..baed8c45cfd2c0f98262696b0afc878e06f3bbca 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -144,6 +144,9 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) throw BError(BError::Codes::SA_INVAL_ARG, "session is nullptr"); } auto backUpConnection = session->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is nullptr"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -327,15 +330,18 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) return EPERM; } auto backUpConnection = session_->GetExtConnection(fileInfo.owner); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is nullptr"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); } ErrCode res = proxy->PublishIncrementalFile(fileInfo.fileName); - if (res) { - HILOGE("Failed to publish file for backup extension"); + if (res != ERR_OK) { + HILOGE("Failed to publish file for backup extension, res:%{public}d", res); } - return res; + return ERR_OK; } catch (const BError &e) { return e.GetCode(); } catch (const exception &e) { @@ -472,13 +478,17 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s auto action = session_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::RUNNING) { auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is empty"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); } int res = proxy->GetIncrementalFileHandle(fileName); - if (res) { - HILOGE("Failed to extension file handle"); + if (res != ERR_OK) { + HILOGE("Failed to extension file handle, res: %{public}d", res); + return res; } } else { SvcRestoreDepsManager::GetInstance().UpdateToRestoreBundleMap(bundleName, fileName); @@ -501,6 +511,9 @@ bool Service::IncrementalBackup(const string &bundleName) HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); IServiceReverse::Scenario scenario = session_->GetScenario(); auto backUpConnection = session_->GetExtConnection(bundleName); + if (backUpConnection == nullptr) { + throw BError(BError::Codes::SA_INVAL_ARG, "backUpConnection is empty"); + } auto proxy = backUpConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index be88cf0e22cf33be53bb54f602456ad999a98781..2b4d2eb0b0117eb84de9c81303b2e4323f671754 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -42,7 +42,12 @@ using namespace std; void SchedScheduler::Sched(string bundleName) { if (bundleName == "") { + if (sessionPtr_ == nullptr) { + HILOGE("Sched bundle %{public}s error, sessionPtr_ is null", bundleName.c_str()); + return; + } if (!sessionPtr_->GetSchedBundleName(bundleName)) { + HILOGE("GetSchedBundleName bundle %{public}s failed", bundleName.c_str()); return; } } @@ -50,6 +55,10 @@ void SchedScheduler::Sched(string bundleName) auto callStart = [schedPtr {wptr(this)}, bundleName]() { try { auto ptr = schedPtr.promote(); + if (ptr == nullptr) { + HILOGE("Sched bundleName %{public}s error, ptr is null", bundleName.data()); + return; + } ptr->ExecutingQueueTasks(bundleName); } catch (const BError &e) { HILOGE("%{public}s", e.what()); @@ -64,7 +73,11 @@ void SchedScheduler::Sched(string bundleName) void SchedScheduler::ExecutingQueueTasks(const string &bundleName) { - HILOGE("start"); + HILOGI("start"); + if (sessionPtr_ == nullptr) { + HILOGE("ExecutingQueueTasks bundle %{public}s error, sessionPtr_ is null", bundleName.c_str()); + return; + } BConstants::ServiceSchedAction action = sessionPtr_->GetServiceSchedAction(bundleName); if (action == BConstants::ServiceSchedAction::START) { // 注册启动定时器 @@ -79,8 +92,11 @@ void SchedScheduler::ExecutingQueueTasks(const string &bundleName) unique_lock lock(lock_); bundleTimeVec_.emplace_back(make_tuple(bundleName, iTime)); lock.unlock(); - // 启动extension - reversePtr_->LaunchBackupExtension(bundleName); + if (reversePtr_ == nullptr) { + HILOGI("Current bundle %{public}s run error, reversePtr_ is null", bundleName.data()); + return; + } + reversePtr_->LaunchBackupExtension(bundleName); // 启动extension } else if (action == BConstants::ServiceSchedAction::RUNNING) { HILOGI("Current bundle %{public}s process is running", bundleName.data()); unique_lock lock(lock_); @@ -92,12 +108,13 @@ void SchedScheduler::ExecutingQueueTasks(const string &bundleName) throw BError(BError::Codes::SA_INVAL_ARG, "Failed to find timer"); } auto &[bName, iTime] = *iter; - // 移除启动定时器 当前逻辑无启动成功后的ext心跳检测 - extTime_.Unregister(iTime); + extTime_.Unregister(iTime); // 移除启动定时器 当前逻辑无启动成功后的ext心跳检测 lock.unlock(); - // 开始执行备份恢复流程 - HILOGI("Current bundle %{public}s extension start", bundleName.data()); - //通知应用市场设置处置 + if (reversePtr_ == nullptr) { + HILOGI("Current bundle %{public}s run error, reversePtr_ is null", bundleName.data()); + return; + } + // 开始执行备份恢复流程,设置处置位 reversePtr_->SendStartAppGalleryNotify(bundleName); reversePtr_->ExtStart(bundleName); } diff --git a/utils/include/b_resources/b_constants.h b/utils/include/b_resources/b_constants.h index bb1ecccbad34865d49603bd7f850f02fa929ba22..e240ed9d393dd993aa71e0440d505d67fddbd249 100644 --- a/utils/include/b_resources/b_constants.h +++ b/utils/include/b_resources/b_constants.h @@ -72,6 +72,8 @@ constexpr int BACKUP_VFS_CACHE_PRESSURE = 10000; // 备份过程修改参数 constexpr int32_t INVALID_FD_NUM = -1; +constexpr int32_t PARAM_STRING_MAX_MEMORY = 2 * 1024 * 1024; + constexpr int MAX_FD_SEND_RATE = 800; // 允许应用申请的最大FD数量 constexpr int MIN_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量 constexpr int DEFAULT_FD_SEND_RATE = 60; // 框架默认的FD数量