diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 7f8f4a2e29b05e5d549f2e2fb2fd99a90e967616..f8fb00a9f92869464c0416a3731c2138769ac30b 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 0000000000000000000000000000000000000000..02e9a40479b8e8254688563db52d3511cbda8e71 --- /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 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /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 0000000000000000000000000000000000000000..f59d7ed35026f3db9a988c63b9bf1f773ad3f423 --- /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 0000000000000000000000000000000000000000..4b3b2ae2824d6bd54c0943d636641f791e473915 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..4848a7836b7b38a19afbf715c34e60b20a137fac --- /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 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..1179705092de33af3dec2add0bb64e1fa075a66b --- /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 0000000000000000000000000000000000000000..b44ef98183c766da5101c0fe0621a5de35b04553 --- /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 0000000000000000000000000000000000000000..dfb620de88ffe0f679b90cd6005a234975397bbb --- /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 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..6ce262d17fd12e39d5cf483f9359f6b948bb1b33 --- /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 0000000000000000000000000000000000000000..0933c44d1ea3b9f799bc6d7201e12da5d070914f --- /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 0000000000000000000000000000000000000000..00187382a739f902b9babb38307e456086388bb8 --- /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 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..99d32a00ea0e56befe2deff2bd73b7c50022c2d9 --- /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 0000000000000000000000000000000000000000..adf86adb37dcb8dc40ac682790c6de5939c54b24 --- /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 0000000000000000000000000000000000000000..c98aaa462860c596c4effb583d7526d94bfc28d8 --- /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 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..eef0b392afc230485a190891cd46a814b5eb94a3 --- /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 0000000000000000000000000000000000000000..1cdaf5386ee7e5260bc303e164a0ca349d036185 --- /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 0000000000000000000000000000000000000000..54b16ed78f00a63d323e14699bd184639e8fba61 --- /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 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..c5f470a678be9c042cd9f2795ad18c99d2131747 --- /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 0000000000000000000000000000000000000000..e14e63397211fb387269448474c1393f288a5396 --- /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 8015efd565608bccd784a300929efd32f9f728e0..22cf7e128c0a211187db86af45f63769458d2a0e 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); } }