From 966ea2e67e58462d3a9b11261aa39383bcd5c3f7 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Tue, 12 Jul 2022 09:10:13 +0800 Subject: [PATCH] fix: modify fuzz test Signed-off-by: wangchaole --- .../native_cpp/test/fuzztest/BUILD.gn | 6 ++ .../onsinklocaldmsdied_fuzzer/BUILD.gn | 78 +++++++++++++++++++ .../onsinklocaldmsdied_fuzzer/corpus/init | 14 ++++ .../onsinklocaldmsdied_fuzzer.cpp | 53 +++++++++++++ .../onsinklocaldmsdied_fuzzer.h | 21 +++++ .../onsinklocaldmsdied_fuzzer/project.xml | 25 ++++++ .../sinkhandlerinitsink_fuzzer/BUILD.gn | 74 ++++++++++++++++++ .../sinkhandlerinitsink_fuzzer/corpus/init | 14 ++++ .../sinkhandlerinitsink_fuzzer/project.xml | 25 ++++++ .../sinkhandlerinitsink_fuzzer.cpp | 48 ++++++++++++ .../sinkhandlerinitsink_fuzzer.h | 21 +++++ .../BUILD.gn | 73 +++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 ++++++ ...nkhandlersubscribelocalhardware_fuzzer.cpp | 49 ++++++++++++ ...sinkhandlersubscribelocalhardware_fuzzer.h | 21 +++++ .../BUILD.gn | 73 +++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 ++++++ ...handlerunsubscribelocalhardware_fuzzer.cpp | 48 ++++++++++++ ...nkhandlerunsubscribelocalhardware_fuzzer.h | 21 +++++ .../BUILD.gn | 72 +++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 ++++++ .../sinkonloadsystemabilityfail_fuzzer.cpp | 49 ++++++++++++ .../sinkonloadsystemabilityfail_fuzzer.h | 22 ++++++ .../BUILD.gn | 72 +++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 ++++++ .../sinkonloadsystemabilitysuccess_fuzzer.cpp | 53 +++++++++++++ .../sinkonloadsystemabilitysuccess_fuzzer.h | 22 ++++++ .../sourceproxydcameranotify_fuzzer.cpp | 2 +- 32 files changed, 1111 insertions(+), 1 deletion(-) create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.h diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 7f8f4a2e..f8fb00a9 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -15,7 +15,13 @@ group("fuzztest") { testonly = true deps = [ + "onsinklocaldmsdied_fuzzer:fuzztest", "onsourcelocaldmsdied_fuzzer:fuzztest", + "sinkhandlerinitsink_fuzzer:fuzztest", + "sinkhandlersubscribelocalhardware_fuzzer:fuzztest", + "sinkhandlerunsubscribelocalhardware_fuzzer:fuzztest", + "sinkonloadsystemabilityfail_fuzzer:fuzztest", + "sinkonloadsystemabilitysuccess_fuzzer:fuzztest", "sourcehandlerconfigdistributedhardware_fuzzer:fuzztest", "sourcehandlerinitsource_fuzzer:fuzztest", "sourcehandlerregisterdistributedhardware_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/BUILD.gn new file mode 100644 index 00000000..02e9a404 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/BUILD.gn @@ -0,0 +1,78 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("OnSinkLocalDmsDiedFuzzTest") { + module_out_path = "distributed_camera/onsinklocaldmsdied" + + fuzz_config_file = + "${innerkits_path}/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "onsinklocaldmsdied_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"OnSinkLocalDmsDiedFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":OnSinkLocalDmsDiedFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.cpp new file mode 100644 index 00000000..f59d7ed3 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 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 "onsinklocaldmsdied_fuzzer.h" + +#include +#include + +#include "dcamera_sink_handler.h" +#include "dcamera_sink_handler_ipc.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void OnSinkLocalDmsDiedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(saId); + wptr remote (remoteObject); + + DCameraSinkHandlerIpc::GetInstance().OnSinkLocalDmsDied(remote); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::OnSinkLocalDmsDiedFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.h new file mode 100644 index 00000000..4b3b2ae2 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/onsinklocaldmsdied_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 ONSINKLOADMSDIED_FUZZER_H +#define ONSINKLOADMSDIED_FUZZER_H + +#define FUZZ_PROJECT_NAME "onsinklocaldmsdied_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsinklocaldmsdied_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn new file mode 100644 index 00000000..4848a783 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn @@ -0,0 +1,74 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerInitSinkFuzzTest") { + module_out_path = "distributed_camera/sinkhandlerinitsink" + + fuzz_config_file = + "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sinkhandlerinitsink_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerInitSinkFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerInitSinkFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp new file mode 100644 index 00000000..11797050 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 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 "sinkhandlerinitsink_fuzzer.h" + +#include +#include + +#include "dcamera_sink_handler.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerInitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + + DCameraSinkHandler::GetInstance().InitSink(params); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerInitSinkFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.h new file mode 100644 index 00000000..b44ef981 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerinitsink_fuzzer/sinkhandlerinitsink_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 SINKHANDLERINITSINK_FUZZER_H +#define SINKHANDLERINITSINK_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerinitsink_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..dfb620de --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerSubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_camera/sinkhandlersubscribelocalhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sinkhandlersubscribelocalhardware_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerSubscribeLocalHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerSubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp new file mode 100644 index 00000000..6ce262d1 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 "sinkhandlersubscribelocalhardware_fuzzer.h" + +#include +#include + +#include "dcamera_sink_handler.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerSubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string param(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + + DCameraSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerSubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.h new file mode 100644 index 00000000..0933c44d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlersubscribelocalhardware_fuzzer/sinkhandlersubscribelocalhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 SINKHANDLERSUBSCRIBELOCALHARDWARE_FUZZER_H +#define SINKHANDLERSUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlersubscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..00187382 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerUnsubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_camera/sinkhandlerunsubscribelocalhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sinkhandlerunsubscribelocalhardware_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerUnsubscribeLocalHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerUnsubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp new file mode 100644 index 00000000..99d32a00 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 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 "sinkhandlerunsubscribelocalhardware_fuzzer.h" + +#include +#include + +#include "dcamera_sink_handler.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerUnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string dhId(reinterpret_cast(data), size); + + DCameraSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerUnsubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.h new file mode 100644 index 00000000..adf86adb --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/sinkhandlerunsubscribelocalhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 SINKHANDLERUNSUBSCRIBELOCALHARDWARE_FUZZER_H +#define SINKHANDLERUNSUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerunsubscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn new file mode 100644 index 00000000..c98aaa46 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkOnLoadSystemAbilityFailFuzzTest") { + module_out_path = "distributed_camera/sinkonloadsystemabilityfail" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sinkonloadsystemabilityfail_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkOnLoadSystemAbilityFailFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkOnLoadSystemAbilityFailFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp new file mode 100644 index 00000000..eef0b392 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 "sinkonloadsystemabilityfail_fuzzer.h" + +#include +#include + +#include "dcamera_sink_load_callback.h" +#include "dcamera_sink_handler.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkOnLoadSystemAbilityFailFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t systemAbilityId = *(reinterpret_cast(data)); + std::string params(reinterpret_cast(data), size); + std::shared_ptr callback = std::make_shared(params); + + callback->OnLoadSystemAbilityFail(systemAbilityId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkOnLoadSystemAbilityFailFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.h new file mode 100644 index 00000000..1cdaf538 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilityfail_fuzzer/sinkonloadsystemabilityfail_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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 SINKONLOADSYSTEMABLITYFAIL_FUZZER_H +#define SINKONLOADSYSTEMABLITYFAIL_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkonloadsystemabilityfail_fuzzer" + +#endif + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn new file mode 100644 index 00000000..54b16ed7 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2022 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/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkOnLoadSystemAbilitySuccessFuzzTest") { + module_out_path = "distributed_camera/sinkonloadsystemabilitysuccess" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sinkonloadsystemabilitysuccess_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkOnLoadSystemAbilitySuccessFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkOnLoadSystemAbilitySuccessFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.cpp new file mode 100644 index 00000000..c5f470a6 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 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 "sinkonloadsystemabilitysuccess_fuzzer.h" + +#include +#include + +#include "dcamera_sink_load_callback.h" +#include "dcamera_sink_handler.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkOnLoadSystemAbilitySuccessFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t systemAbilityId = *(reinterpret_cast(data)); + std::string params(reinterpret_cast(data), size); + std::shared_ptr callback = std::make_shared(params); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(systemAbilityId); + + callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkOnLoadSystemAbilitySuccessFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.h new file mode 100644 index 00000000..e14e6339 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkonloadsystemabilitysuccess_fuzzer/sinkonloadsystemabilitysuccess_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 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 SINKONLOADSYSTEMABLITYSUCESS_FUZZER_H +#define SINKONLOADSYSTEMABLITYSUCESS_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkonloadsystemabilitysuccess_fuzzer" + +#endif + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp index 8015efd5..22cf7e12 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp @@ -45,7 +45,7 @@ void SourceProxyDCameraNotifyFuzzTest(const uint8_t* data, size_t size) sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); std::shared_ptr dCSourceProxy = std::make_shared(remoteObject); - sptr callback = new DCameraSourceCallback(); + dCSourceProxy->DCameraNotify(devId, dhId, events); } } -- Gitee