diff --git a/bundle.json b/bundle.json index 1450c5d7b226b476a804a9e358292dbe68628b9a..88b29c98352032e02d50a30b81e21cd7d0f25159 100644 --- a/bundle.json +++ b/bundle.json @@ -90,7 +90,8 @@ "//foundation/distributedhardware/distributedcamera/services/cameraservice/cameraoperator/handler/test/unittest:camera_handler_test", "//foundation/distributedhardware/distributedcamera/services/cameraservice/sinkservice/test/unittest:sink_service_test", "//foundation/distributedhardware/distributedcamera/services/cameraservice/sourceservice/test/unittest:source_service_test", - "//foundation/distributedhardware/distributedcamera/services/cameraservice/base/test/unittest:services_base_test" + "//foundation/distributedhardware/distributedcamera/services/cameraservice/base/test/unittest:services_base_test", + "//foundation/distributedhardware/distributedcamera/interfaces/inner_kits/native_cpp/test/fuzztest:fuzztest" ] } } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d6d3d2ca6664f5b02097c7d0a00618c0efff67f1 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -0,0 +1,24 @@ +# 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. + +group("fuzztest") { + testonly = true + + deps = [ + "dcamerasinkhandleripc_fuzzer:fuzztest", + "dcamerasinkloadcallback_fuzzer:fuzztest", + "dcamerasinkproxy_fuzzer:fuzztest", + "dcamerasourcehandleripc_fuzzer:fuzztest", + "dcamerasourceloadcallback_fuzzer:fuzztest", + ] +} diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..747a76d40db6472414be2b51939510cde4e22a72 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/BUILD.gn @@ -0,0 +1,78 @@ +# Copyright (c) 2021 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/distributedcamera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DCameraSinkHandlerIpcFuzzTest") { + module_out_path = "distributed_camera/dcamerasinkhandleripc" + + fuzz_config_file = + "${innerkits_path}/native_cpp/test/fuzztest/dcamerasinkhandleripc_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 = [ "dcamera_sink_handler_ipc_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=\"DCameraSinkHandlerIpcFuzzTest\"", + "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 = [ ":DCameraSinkHandlerIpcFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_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/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0948021e99014dc15595c084edf92043323a9697 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "dcamera_sink_handler_ipc_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 DCameraSinkHandlerIpcFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); + wptr remote (remoteObject); + + DCameraSinkHandlerIpc::GetInstance().Init(); + DCameraSinkHandlerIpc::GetInstance().GetSinkLocalDHMS(); + DCameraSinkHandlerIpc::GetInstance().OnSinkLocalDmsDied(remote); + DCameraSinkHandlerIpc::GetInstance().UnInit(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DCameraSinkHandlerIpcFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0e64ca3c8c5a3312b1d8f4ce7ad5e2f450167ad3 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_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 DCAMERA_SINK_HANDLER_IPC_FUZZER_H +#define DCAMERA_SINK_HANDLER_IPC_FUZZER_H + +#define FUZZ_PROJECT_NAME "dcamera_sink_handler_ipc_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a797f4485bf9dcbda5d464d056f09f17bc28fe6b --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2021 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/distributedcamera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DCameraSinkLoadCallbackFuzzTest") { + module_out_path = "distributed_camera/dcamerasinkloadcallback" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/dcamerasinkloadcallback_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 = [ "dcamera_sink_load_callback_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=\"DCameraSinkLoadCallbackFuzzTest\"", + "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 = [ ":DCameraSinkLoadCallbackFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_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/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fa97f98799a6a55e5d555a1bad03a2f177dce116 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "dcamera_sink_load_callback_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 DCameraSinkLoadCallbackFuzzTest(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(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); + + callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); + callback->OnLoadSystemAbilityFail(systemAbilityId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DCameraSinkLoadCallbackFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d79eee8ded58d8ee794872c7b543935323a03aff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_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 DCAMERA_SINK_LOAD_CALLBACK_FUZZER_H +#define DCAMERA_SINK_LOAD_CALLBACK_FUZZER_H + +#define FUZZ_PROJECT_NAME "dcamera_sink_load_callback_fuzzer" + +#endif + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..853342744ea527071a4ed139dd5da9bcfa110f2b --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 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/distributedcamera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DCameraSinkProxyFuzzTest") { + module_out_path = "distributed_camera/dcamerasinkproxy" + + fuzz_config_file = + "${innerkits_path}/native_cpp/test/fuzztest/dcamerasinkproxy_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 = [ "dcamera_sink_proxy_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=\"DCameraSinkProxyFuzzTest\"", + "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 = [ ":DCameraSinkProxyFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_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/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85395ace951a4c6b5ede268b6cad7be77bfadad7 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.cpp @@ -0,0 +1,68 @@ +/* + * 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 "dcamera_sink_proxy_fuzzer.h" + +#include +#include + +#include "distributed_camera_constants.h" +#include "distributed_camera_sink_proxy.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DCameraSinkProxyFuzzTest(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); + std::string params(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string channelInfo(reinterpret_cast(data), size); + std::string cameraInfo(reinterpret_cast(data), size); + std::string openInfo(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); + std::shared_ptr dCSinkProxy = + std::make_shared(remoteObject); + + dCSinkProxy->InitSink(param); + dCSinkProxy->SubscribeLocalHardware(dhId, params); + dCSinkProxy->ChannelNeg(dhId, channelInfo); + dCSinkProxy->GetCameraInfo(dhId, cameraInfo); + dCSinkProxy->OpenChannel(dhId, openInfo); + dCSinkProxy->CloseChannel(dhId); + dCSinkProxy->UnsubscribeLocalHardware(dhId); + dCSinkProxy->StopCapture(dhId); + dCSinkProxy->ReleaseSink(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DCameraSinkProxyFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2b956a3f5c6fe44ed00577dd68c564d2c48da855 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_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 DCAMERA_SINK_PROXY_FUZZER_H +#define DCAMERA_SINK_PROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "dcamera_sink_proxy_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..637c2d87a13540235d6d8144b3e1df529e74398e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2021 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/distributedcamera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DCameraSourceHandlerIpcFuzzTest") { + module_out_path = "distributed_camera/dcamerasourcehandleripc" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dcamera_source_handler_ipc_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DCameraSourceHandlerIpcFuzzTest\"", + "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 = [ ":DCameraSourceHandlerIpcFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_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/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..471e321d01c06e44766f6ec935f2cd243d1c9fa0 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "dcamera_source_handler_ipc_fuzzer.h" + +#include +#include + +#include "dcamera_source_handler.h" +#include "dcamera_source_handler_ipc.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DCameraSourceHandlerIpcFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + wptr remote (remoteObject); + + DCameraSourceHandlerIpc::GetInstance().Init(); + DCameraSourceHandlerIpc::GetInstance().GetSourceLocalDHMS(); + DCameraSourceHandlerIpc::GetInstance().OnSourceLocalDmsDied(remote); + DCameraSourceHandlerIpc::GetInstance().UnInit(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DCameraSourceHandlerIpcFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6bc5b6943821b348a5539913433995501b12c341 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_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 DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H +#define DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H + +#define FUZZ_PROJECT_NAME "dcamera_source_handler_ipc_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..61b9eb72068d2c5c5b146ccfadb822c4349fc4b0 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 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/distributedcamera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DCameraSourceLoadCallbackFuzzTest") { + module_out_path = "distributed_camera/dcamerasourceloadcallback" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dcamera_source_load_callback_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DCameraSourceLoadCallbackFuzzTest\"", + "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 = [ ":DCameraSourceLoadCallbackFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_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/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad4ef5ac98dfd768a19d6b92bc6477a972ec4f22 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "dcamera_source_load_callback_fuzzer.h" + +#include +#include + +#include "dcamera_source_load_callback.h" +#include "dcamera_source_handler.h" +#include "distributed_camera_constants.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DCameraSourceLoadCallbackFuzzTest(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(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + + callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); + callback->OnLoadSystemAbilityFail(systemAbilityId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DCameraSourceLoadCallbackFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e50a28e5df22c9b0123273bbdb2ac714368a9720 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_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 DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H +#define DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H + +#define FUZZ_PROJECT_NAME "dcamera_source_load_callback_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +