From d55a386f3bc33327abe9f1d4ad5fdb7c527e86b3 Mon Sep 17 00:00:00 2001 From: wangpggg Date: Tue, 21 Jan 2025 18:00:33 +0800 Subject: [PATCH] modify failed fuzz testcase Signed-off-by: wangpeng --- .../backupservicestubbranch_fuzzer/BUILD.gn | 1 + .../backupservicestubbranch_fuzzer.cpp | 18 ++-- .../backupservicestubbranch_fuzzer.h | 2 +- .../backupservicestubbranch_fuzzer/service.h | 87 +++++++++++++++++++ 4 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 test/fuzztest/backupservicestubbranch_fuzzer/service.h diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn index 72b6e4f44..dcaad28f4 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn +++ b/test/fuzztest/backupservicestubbranch_fuzzer/BUILD.gn @@ -51,6 +51,7 @@ ohos_fuzztest("BackupServiceStubBranchFuzzTest") { "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] defines = [ diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp index e55581028..5b788a6cb 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.cpp +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.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 @@ -15,7 +15,7 @@ #include "backupservicestubbranch_fuzzer.h" -#include +#include #include #include "b_incremental_data.h" @@ -28,6 +28,7 @@ namespace OHOS { using namespace FileManagement::Backup; +using namespace std; using FAFVariant = std::variant>; @@ -192,7 +193,6 @@ bool Parcel::ReadUint32(uint32_t &value) return GetBoolResult(); } -constexpr int32_t SERVICE_ID = 5203; template T TypeCast(const uint8_t *data, int *pos = nullptr) @@ -965,20 +965,18 @@ bool CmdGetBackupInfoFuzzTest(sptr service, const uint8_t *data, size_t MessageParcel reply; try { - int pos = 0; - int32_t scenario = TypeCast(data, &pos); - string processInfo(reinterpret_cast(data + pos), size - pos); + string bundleName(reinterpret_cast(data), size); ExpectReturn({false}); - ExpectArgReturn({processInfo}); + ExpectArgReturn({bundleName}); service->CmdGetBackupInfo(msg, reply); ExpectReturn({true, false}); - ExpectArgReturn({processInfo, scenario}); + ExpectArgReturn({bundleName}); service->CmdGetBackupInfo(msg, reply); ExpectReturn({true, true}); - ExpectArgReturn({processInfo, scenario}); + ExpectArgReturn({bundleName}); service->CmdGetBackupInfo(msg, reply); } catch (OHOS::FileManagement::Backup::BError &err) { // Only filter BError errors, Other results are not expected. @@ -1060,7 +1058,7 @@ bool CmdUpdateSendRateFuzzTest(sptr service, const uint8_t *data, size_ /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::sptr service(new OHOS::FileManagement::Backup::Service(OHOS::SERVICE_ID)); + OHOS::sptr service(new OHOS::FileManagement::Backup::Service()); if (service == nullptr) { return 0; } diff --git a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h index e1a5fcc77..7e7ba1c46 100644 --- a/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h +++ b/test/fuzztest/backupservicestubbranch_fuzzer/backupservicestubbranch_fuzzer.h @@ -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/test/fuzztest/backupservicestubbranch_fuzzer/service.h b/test/fuzztest/backupservicestubbranch_fuzzer/service.h new file mode 100644 index 000000000..6d074c8e3 --- /dev/null +++ b/test/fuzztest/backupservicestubbranch_fuzzer/service.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FILEMGMT_BACKUP_SERVICE_H +#define OHOS_FILEMGMT_BACKUP_SERVICE_H + +#include +#include + +#include "b_error/b_error.h" +#include "i_service_reverse.h" +#include "iremote_stub.h" +#include "service_stub.h" + +namespace OHOS::FileManagement::Backup { +class Service : public ServiceStub { +public: + ErrCode InitRestoreSession(sptr) { return BError(BError::Codes::OK); } + ErrCode InitRestoreSession(sptr, std::string&) { return BError(BError::Codes::OK); } + ErrCode InitBackupSession(sptr) { return BError(BError::Codes::OK); } + ErrCode InitBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } + ErrCode Start() { return BError(BError::Codes::OK); } + UniqueFd GetLocalCapabilities() { return UniqueFd(-1); } + UniqueFd GetLocalCapabilitiesForBundleInfos() { return UniqueFd(-1); } + ErrCode PublishFile(const BFileInfo&) { return BError(BError::Codes::OK); } + ErrCode AppFileReady(const std::string&, UniqueFd, int32_t) { return BError(BError::Codes::OK); } + ErrCode AppDone(ErrCode) { return BError(BError::Codes::OK); } + ErrCode ServiceResultReport(const std::string, + BackupRestoreScenario, ErrCode) { return BError(BError::Codes::OK); } + ErrCode GetFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesRestoreSession(UniqueFd, + const std::vector&, + const std::vector&, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesRestoreSession(UniqueFd, + const std::vector&, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesBackupSession(const std::vector&) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesDetailsBackupSession(const std::vector&, + const std::vector&) { return BError(BError::Codes::OK); } + ErrCode Finish() { return BError(BError::Codes::OK); } + ErrCode Release() { return BError(BError::Codes::OK); } + ErrCode Cancel(std::string, int32_t&) { return BError(BError::Codes::OK); } + UniqueFd GetLocalCapabilitiesIncremental(const std::vector&) { return UniqueFd(-1); } + ErrCode GetAppLocalListAndDoIncrementalBackup() { return BError(BError::Codes::OK); } + ErrCode InitIncrementalBackupSession(sptr) { return BError(BError::Codes::OK); } + ErrCode InitIncrementalBackupSession(sptr, std::string&) { return BError(BError::Codes::OK); } + ErrCode AppendBundlesIncrementalBackupSession(const std::vector&) + { return BError(BError::Codes::OK); } + ErrCode AppendBundlesIncrementalBackupSession(const std::vector&, const std::vector&) + { return BError(BError::Codes::OK); } + ErrCode PublishIncrementalFile(const BFileInfo&) { return BError(BError::Codes::OK); } + ErrCode PublishSAIncrementalFile(const BFileInfo&, UniqueFd) { return BError(BError::Codes::OK); } + ErrCode AppIncrementalFileReady(const std::string&, UniqueFd, UniqueFd, int32_t) + { return BError(BError::Codes::OK); } + ErrCode AppIncrementalDone(ErrCode) { return BError(BError::Codes::OK); } + ErrCode GetIncrementalFileHandle(const std::string&, const std::string&) { return BError(BError::Codes::OK); } + ErrCode GetBackupInfo(BundleName&, std::string&) { return BError(BError::Codes::OK); } + ErrCode UpdateTimer(BundleName&, uint32_t, bool&) { return BError(BError::Codes::OK); } + ErrCode UpdateSendRate(std::string&, int32_t, bool&) { return BError(BError::Codes::OK); } + ErrCode ReportAppProcessInfo(const std::string, const BackupRestoreScenario) { return BError(BError::Codes::OK); } + ErrCode StartExtTimer(bool&) { return BError(BError::Codes::OK); } + ErrCode StartFwkTimer(bool&) { return BError(BError::Codes::OK); } + ErrCode StopExtTimer(bool&) { return BError(BError::Codes::OK); } + ErrCode RefreshDataSize(int64_t) { return BError(BError::Codes::OK); } + + ErrCode SAResultReport(const std::string, const std::string, + const ErrCode, const BackupRestoreScenario) { return BError(BError::Codes::OK); } + ErrCode GetBackupDataSize(bool, std::vector) { return BError(BError::Codes::OK); } +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_SERVICE_H \ No newline at end of file -- Gitee