From e6897474087f82f7b72fddf917bbcfdfd7cf4382 Mon Sep 17 00:00:00 2001 From: wangchaole Date: Thu, 27 Oct 2022 09:03:39 +0800 Subject: [PATCH] fix: add fuzztest Signed-off-by: wangchaole --- .../native_cpp/test/fuzztest/BUILD.gn | 3 + .../callbackonnotifyregresult_fuzzer/BUILD.gn | 75 +++++++++++++++++++ .../callbackonnotifyregresult_fuzzer.cpp | 50 +++++++++++++ .../callbackonnotifyregresult_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../BUILD.gn | 75 +++++++++++++++++++ .../callbackonnotifyunregresult_fuzzer.cpp | 50 +++++++++++++ .../callbackonnotifyunregresult_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../callbackonremoterequest_fuzzer/BUILD.gn | 74 ++++++++++++++++++ .../callbackonremoterequest_fuzzer.cpp | 61 +++++++++++++++ .../callbackonremoterequest_fuzzer.h | 21 ++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ 16 files changed, 568 insertions(+) create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/project.xml diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 3ef21ccc..ec61db62 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -15,6 +15,9 @@ group("fuzztest") { testonly = true deps = [ + "callbackonnotifyregresult_fuzzer:fuzztest", + "callbackonnotifyunregresult_fuzzer:fuzztest", + "callbackonremoterequest_fuzzer:fuzztest", "onsinklocalcamsrvdied_fuzzer:fuzztest", "onsourcelocalcamsrvdied_fuzzer:fuzztest", "sinkhandlerinitsink_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/BUILD.gn new file mode 100644 index 00000000..b5e1e843 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# 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("CallbackOnNotifyRegResultFuzzTest") { + module_out_path = "distributed_camera/callbackonnotifyregresult" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/callbackonnotifyregresult_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", + "${innerkits_path}/native_cpp/test/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "callbackonnotifyregresult_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CallbackOnNotifyRegResultFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":CallbackOnNotifyRegResultFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp new file mode 100644 index 00000000..b7c811d9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 "callbackonnotifyregresult_fuzzer.h" + +#include "dcamera_source_callback.h" +#include "distributed_camera_constants.h" +#include "mock_component_enable.h" + +namespace OHOS { +namespace DistributedHardware { +void CallbackOnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + int32_t status = *(reinterpret_cast(data)); + std::string dataStr(reinterpret_cast(data), size); + std::shared_ptr callback = std::make_shared(); + + sptr dcameraSourceCallback = new (std::nothrow) DCameraSourceCallback(); + dcameraSourceCallback->PushRegCallback(reqId, callback); + dcameraSourceCallback->OnNotifyRegResult(devId, dhId, reqId, status, dataStr); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::CallbackOnNotifyRegResultFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_fuzzer.h new file mode 100644 index 00000000..9f11c603 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/callbackonnotifyregresult_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 CALLBACKONNOtIFYREGRESULT_FUZZER_H +#define CALLBACKONNOtIFYREGRESULT_FUZZER_H + +#define FUZZ_PROJECT_NAME "callbackonnotifyregresult_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_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/callbackonnotifyregresult_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyregresult_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/BUILD.gn new file mode 100644 index 00000000..ea946c15 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# 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("CallbackOnNotifyUnRegResultFuzzTest") { + module_out_path = "distributed_camera/callbackonnotifyunregresult" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/callbackonnotifyunregresult_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", + "${innerkits_path}/native_cpp/test/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "callbackonnotifyunregresult_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CallbackOnNotifyUnRegResultFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":CallbackOnNotifyUnRegResultFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp new file mode 100644 index 00000000..43067f0e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 "callbackonnotifyunregresult_fuzzer.h" + +#include "dcamera_source_callback.h" +#include "distributed_camera_constants.h" +#include "mock_component_disable.h" + +namespace OHOS { +namespace DistributedHardware { +void CallbackOnNotifyRegResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + int32_t status = *(reinterpret_cast(data)); + std::string dataStr(reinterpret_cast(data), size); + std::shared_ptr uncallback = std::make_shared(); + + sptr dcameraSourceCallback = new (std::nothrow) DCameraSourceCallback(); + dcameraSourceCallback->PushUnregCallback(reqId, uncallback); + dcameraSourceCallback->OnNotifyRegResult(devId, dhId, reqId, status, dataStr); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::CallbackOnNotifyRegResultFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_fuzzer.h new file mode 100644 index 00000000..d014cf26 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/callbackonnotifyunregresult_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 CALLBACKONNOtIFYUNREGRESULT_FUZZER_H +#define CALLBACKONNOtIFYUNREGRESULT_FUZZER_H + +#define FUZZ_PROJECT_NAME "callbackonnotifyunregresult_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_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/callbackonnotifyunregresult_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonnotifyunregresult_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/BUILD.gn new file mode 100644 index 00000000..830a3d7f --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_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("CallbackOnRemoteRequestFuzzTest") { + module_out_path = "distributed_camera/callbackonremoterequest" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/callbackonremoterequest_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", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "callbackonremoterequest_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"CallbackOnRemoteRequestFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":CallbackOnRemoteRequestFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp new file mode 100644 index 00000000..854c7ac7 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * 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 "callbackonremoterequest_fuzzer.h" + +#include "dcamera_source_callback.h" +#include "dcamera_source_callback_stub.h" +#include "distributed_camera_constants.h" +#include "iremote_object.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace DistributedHardware { +void CallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + uint32_t code = *(reinterpret_cast(data)) % 2; + int32_t status = *(reinterpret_cast(data)); + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string dataStr(reinterpret_cast(data), size); + pdata.WriteInt32(status); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteString(dataStr); + + sptr dcameraSourceCallback = new (std::nothrow) DCameraSourceCallback(); + dcameraSourceCallback->OnRemoteRequest(code, pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::CallbackOnRemoteRequestFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_fuzzer.h new file mode 100644 index 00000000..05ff48f2 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/callbackonremoterequest_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 CALLBACKONREMOTEREQUEST_FUZZER_H +#define CALLBACKONREMOTEREQUEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "callbackonremoterequest_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_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/callbackonremoterequest_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/callbackonremoterequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee