diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b48c7a195d793454391edaf9eaa53ce8fdd1b28e..b59d6824a17a89ea5baeeae0ae8d3ea1d84c53b6 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1650,6 +1650,12 @@ ErrCode Service::GetBackupInfoCmdHandle(BundleName &bundleName, std::string &res ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) { + ErrCode errCode = VerifyCaller(); + if (errCode != ERR_OK) { + HILOGE("GetBackupInfo failed, verify caller failed, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); + return errCode; + } try { std::lock_guard lock(getBackupInfoProcLock_); HILOGI("Service::GetBackupInfo begin."); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index b867846522e5af35d3451de5785143b58a0c6897..3f1137de5c7984156d809c43061aefbef64841c7 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -521,6 +521,12 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) { std::string bundleName = fileInfo.owner; + ErrCode errCode = VerifyCaller(); + if (errCode != ERR_OK) { + HILOGE("PublishSAIncrementalFile failed, verify caller failed, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); + return errCode; + } if (!SAUtils::IsSABundleName(bundleName)) { HILOGE("Bundle name %{public}s is not sa", bundleName.c_str()); return BError(BError::Codes::SA_EXT_ERR_CALL); diff --git a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp index 05bd4ba713fd973746a164da5c08e4332ddb00bb..158372cd2bb4d211b10792c33f36ac5cf4b0d258 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -801,13 +801,18 @@ HWTEST_F(ServiceThrowTest, SUB_Service_throw_GetBackupInfo_0100, testing::ext::T EXPECT_NE(service, nullptr); BundleName bundleName; string result; + EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::DEFAULT_USER_ID)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); + EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); + EXPECT_CALL(*param, GetBackupDebugOverrideAccount()) + .WillOnce(Return(make_pair(true, DEBUG_ID + 1))); EXPECT_CALL(*sessionMock, GetImpl()).WillOnce(Invoke([]() { throw "未知错误"; return SvcSessionManager::Impl(); })); EXPECT_CALL(*sessionMock, DecreaseSessionCnt(_)).WillOnce(Return()); auto ret = service->GetBackupInfo(bundleName, result); - EXPECT_EQ(ret, EPERM); + EXPECT_NE(ret, EPERM); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "ServiceThrowTest-an exception occurred by GetBackupInfo.";