From 0f58b63f67ebfddab9da4e9c75f9e13b7cb5dd1f Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 17 Feb 2025 15:38:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=20Signed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/backup_sa/src/module_ipc/service.cpp | 5 +++++ services/backup_sa/src/module_ipc/service_incremental.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b48c7a195..9b79cc759 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1650,6 +1650,11 @@ 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, errCode:%{public}d", 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 b86784652..a4767ee9f 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -520,6 +520,11 @@ ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo) ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd) { + ErrCode errCode = VerifyCaller(); + if (errCode != ERR_OK) { + HILOGE("PublishSAIncrementalFile failed, verify caller failed, errCode:%{public}d", errCode); + return errCode; + } std::string bundleName = fileInfo.owner; if (!SAUtils::IsSABundleName(bundleName)) { HILOGE("Bundle name %{public}s is not sa", bundleName.c_str()); -- Gitee From 538a29ecbd0271c2ad4c15821edfb8b14fcb7de4 Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 18 Feb 2025 09:19:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9ut=20Signed-off-by:=20che?= =?UTF-8?q?nsihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unittests/backup_sa/module_ipc/service_throw_test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 05bd4ba71..f73b63f80 100644 --- a/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_throw_test.cpp @@ -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."; -- Gitee From a24046a58676c8da4012619ac537e22780eacb92 Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 18 Feb 2025 14:19:57 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8C=85=E5=90=8D?= =?UTF-8?q?=E6=89=93=E5=8D=B0=20Signed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/backup_sa/src/module_ipc/service.cpp | 3 ++- services/backup_sa/src/module_ipc/service_incremental.cpp | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 9b79cc759..8df237fe7 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1652,7 +1652,8 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) { ErrCode errCode = VerifyCaller(); if (errCode != ERR_OK) { - HILOGE("GetBackupInfo failed, verify caller failed, errCode:%{public}d", errCode); + HILOGE("GetBackupInfo failed, verify caller failed, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); return errCode; } try { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index a4767ee9f..e51058b6b 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -520,12 +520,13 @@ 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, errCode:%{public}d", errCode); + HILOGE("PublishSAIncrementalFile failed, verify caller failed, bundleName:%{public}s, errCode:%{public}d", + bundleName.c_str(), errCode); return errCode; } - std::string bundleName = fileInfo.owner; if (!SAUtils::IsSABundleName(bundleName)) { HILOGE("Bundle name %{public}s is not sa", bundleName.c_str()); return BError(BError::Codes::SA_EXT_ERR_CALL); -- Gitee From bc48fbacc8ef09b2aa414850bee614ae2b9ba2cc Mon Sep 17 00:00:00 2001 From: chensihan Date: Tue, 18 Feb 2025 15:59:03 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8A=A0=E7=89=88=E6=9D=83=E5=A4=B4=20Sign?= =?UTF-8?q?ed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/backup_sa/src/module_ipc/service.cpp | 2 +- services/backup_sa/src/module_ipc/service_incremental.cpp | 2 +- tests/unittests/backup_sa/module_ipc/service_throw_test.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 8df237fe7..b59d6824a 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 diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index e51058b6b..3f1137de5 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 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 f73b63f80..158372cd2 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 -- Gitee