diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 12a10c0b2c6688fc270132b544a0cfc7be9cad0d..991b0ae6b4ddde95e0ae503b1f8fe60dd4a1a44e 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,6 +18,7 @@ group("fuzztest") { # deps file "backupext_fuzzer:BackupExtFuzzTest", "backupsa_fuzzer:BackupSaFuzzTest", + "backupsaappend_fuzzer:BackupSaAppendFuzzTest", "fileshare_fuzzer:FileShareFuzzTest", "remotefileshare_fuzzer:RemoteFileShareFuzzTest", "servicereverse_fuzzer:ServiceReverseFuzzTest", diff --git a/test/fuzztest/backupsaappend_fuzzer/BUILD.gn b/test/fuzztest/backupsaappend_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c7ae508b0505f487c2e21c3a4dce750b519cdd13 --- /dev/null +++ b/test/fuzztest/backupsaappend_fuzzer/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2021-2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/app_file_service/app_file_service.gni") +import("//foundation/filemanagement/app_file_service/backup.gni") + +##############################fuzztest########################################## +ohos_fuzztest("BackupSaAppendFuzzTest") { + module_out_path = "app_file_service/app_file_service" + fuzz_config_file = + "${app_file_service_path}/test/fuzztest/backupsaappend_fuzzer" + include_dirs = [ + "${app_file_service_path}/services/backup_sa/include/module_ipc", + "${app_file_service_path}/services/backup_sa/include", + "${app_file_service_path}/interfaces/inner_api/native/backup_kit_inner/impl", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "backupsaappend_fuzzer.cpp" ] + + deps = [ + "${app_file_service_path}/services/backup_sa:backup_sa", + "${path_backup}/utils:backup_utils", + "${third_party_path}/bounds_checking_function:libsec_shared", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "c_utils:utils", + "file_api:filemgmt_libn", + "hilog:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "LOG_TAG=\"app_file_service\"", + "LOG_DOMAIN=0xD200000", + ] +} +############################################################################### diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b741dc24cafa34a72da845c85ed2a751b8deb09c --- /dev/null +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 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. + */ + +#include "backupsaappend_fuzzer.h" + +#include +#include +#include + +#include +#include "message_parcel.h" +#include "service_stub.h" +#include "service.h" +#include "securec.h" +#include "system_ability.h" + +using namespace OHOS::FileManagement::Backup; + +namespace OHOS { +constexpr int32_t SERVICE_ID = 5203; + +bool CmdStartFuzzTest(const uint8_t *data, size_t size) +{ + MessageParcel datas; + datas.WriteInterfaceToken(ServiceStub::GetDescriptor()); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + + sptr service = sptr(new Service(SERVICE_ID)); + service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_START), + datas, reply, option); + service = nullptr; + return true; +} + +bool CmdFinishFuzzTest(const uint8_t *data, size_t size) +{ + MessageParcel datas; + datas.WriteInterfaceToken(ServiceStub::GetDescriptor()); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + + sptr service = sptr(new Service(SERVICE_ID)); + service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH), + datas, reply, option); + service = nullptr; + return true; +} + +bool CmdAppendBundlesRestoreSessionFuzzTest(const uint8_t *data, size_t size) +{ + MessageParcel datas; + datas.WriteInterfaceToken(ServiceStub::GetDescriptor()); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + + sptr service = sptr(new Service(SERVICE_ID)); + service->OnRemoteRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), + datas, reply, option); + service = nullptr; + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + OHOS::CmdStartFuzzTest(data, size); + OHOS::CmdFinishFuzzTest(data, size); + OHOS::CmdAppendBundlesRestoreSessionFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.h b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8ddfc2126b559d055ee576338bf4e3ca548e75f9 --- /dev/null +++ b/test/fuzztest/backupsaappend_fuzzer/backupsaappend_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 BACKUPSAAPPEND_FUZZER_H +#define BACKUPSAAPPEND_FUZZER_H + +#define FUZZ_PROJECT_NAME "backupsaappend_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backupsaappend_fuzzer/corpus/init b/test/fuzztest/backupsaappend_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/test/fuzztest/backupsaappend_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/backupsaappend_fuzzer/project.xml b/test/fuzztest/backupsaappend_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/test/fuzztest/backupsaappend_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/servicereverse_fuzzer/servicereverse_fuzzer.cpp b/test/fuzztest/servicereverse_fuzzer/servicereverse_fuzzer.cpp index ed6db23232406775cf08d5063a5ea222c2533515..5ad5da0877699e51d0b6ec32f05f8c0dad85f166 100644 --- a/test/fuzztest/servicereverse_fuzzer/servicereverse_fuzzer.cpp +++ b/test/fuzztest/servicereverse_fuzzer/servicereverse_fuzzer.cpp @@ -155,11 +155,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) return 0; } - auto str = std::make_unique(size + 1); - (void)memset_s(str.get(), size + 1, 0x00, size + 1); - if (memcpy_s(str.get(), size, data, size) != EOK) { - return 0; - } OHOS::BackupFuzzTest(data, size); OHOS::RestoreFuzzTest(data, size); OHOS::IncrementalBackupFuzzTest(data, size);