diff --git a/bundle.json b/bundle.json index b6d72ecfff21cdeb9e0b8493e75a298889c2a5b0..2fe302a94227d0cc229d01f917010568fd832f8f 100644 --- a/bundle.json +++ b/bundle.json @@ -65,7 +65,8 @@ } ], "test": [ - "//foundation/distributedhardware/devicemanager/test:test" + "//foundation/distributedhardware/devicemanager/test:test", + "//foundation/distributedhardware/devicemanager/fuzztest:fuzztest" ] } } diff --git a/test/BUILD.gn b/test/BUILD.gn index 87552dc685b4bef675733a99a5209267d271b51f..95b10dcae105a5e01eb62057bc6cc5d4534e9c60 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -16,6 +16,9 @@ group("test") { deps = [] if (support_jsapi) { - deps += [ "unittest:unittest" ] + deps += [ + "unittest:unittest", + "fuzztest:fuzztest" + ] } } diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e57c94b3a43b356ae8e9a68d56ed024c8978e8e2 --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,28 @@ +# 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 = [ + "devicemanagerimpl_fuzzer:fuzztest", + "devicemanagernotify_fuzzer:fuzztest", + "devicemanagerservice_fuzzer:fuzztest", + "ipcclientmanager_fuzzer:fuzztest", + "ipccmdregister_fuzzer:fuzztest", + "ipcserverclientproxy_fuzzer:fuzztest", + "ipcserverlistener_fuzzer:fuzztest", + "ipcserverstub_fuzzer:fuzztest", + "nativedevicemanagerjs_fuzzer:fuzztest", + ] +} \ No newline at end of file diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn b/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b5cc8ca335293182949129c0d90b44d2b8ac3f40 --- /dev/null +++ b/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn @@ -0,0 +1,133 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DeviceManagerImplFuzzTest") { + module_out_path = "devicemanager/devicemanagerimpl_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/devicemanagerimpl_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${services_path}/include", + "${services_path}/include/dependency/timer", + "${services_path}/include/discovery", + "${services_path}/include/dependency/softbus", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo/", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "device_manager_impl_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "${utils_path}:devicemanagerutils", + "//foundation/ace/napi:ace_napi", + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DeviceManagerImplFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DeviceManagerImplFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/corpus/init b/test/fuzztest/devicemanagerimpl_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/devicemanagerimpl_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp b/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5bcdbaeb647eb940a195b7e8f060ef12f3ad7e7 --- /dev/null +++ b/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp @@ -0,0 +1,252 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include "device_manager_impl.h" +#include "device_manager.h" +#include "dm_constants.h" +#include "dm_log.h" +#include "device_manager_callback.h" +#include "dm_app_image_info.h" +#include "dm_device_info.h" +#include "dm_native_event.h" +#include "dm_subscribe_info.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "nlohmann/json.hpp" +#include "native_devicemanager_js.h" +#include "device_manager_impl_fuzzer.h" + +const int nCapabiltyBufferSize = 65; + +namespace OHOS { +namespace DistributedHardware { +void InitDeviceManagerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string packName(reinterpret_cast(data), size); + std::string bundleName(reinterpret_cast(data), size); + napi_env env; + std::shared_ptr initCallback = std::make_shared(env, bundleName); + + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, initCallback); + ret = DeviceManager::GetInstance().UnInitDeviceManager(packName); +} + +void DeviceListFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string extra(reinterpret_cast(data), size); + std::vector devList; + std::string bundleName(reinterpret_cast(data), size); + DmDeviceInfo deviceInfo; + + int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(bundleName, extra, devList); + ret = DeviceManager::GetInstance().GetLocalDeviceInfo(bundleName, deviceInfo); +} + +void DeviceDiscoveryFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string bundleName(reinterpret_cast(data), size); + + DmSubscribeInfo subInfo; + subInfo.subscribeId = *(reinterpret_cast(data)); + subInfo.mode = *(reinterpret_cast(data)); + subInfo.medium = *(reinterpret_cast(data)); + subInfo.freq = *(reinterpret_cast(data)); + subInfo.isSameAccount = *(reinterpret_cast(data)); + subInfo.isWakeRemote = *(reinterpret_cast(data)); + strncpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, (char*)data, nCapabiltyBufferSize); + napi_env env; + std::string extra(reinterpret_cast(data), size); + int16_t subscribeId = *(reinterpret_cast(data)); + std::shared_ptr discoverCallback = + std::make_shared(env, bundleName); + + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName, + subInfo, extra, discoverCallback); + ret = DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId); +} + +void AuthenticateDeviceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string pkgName(reinterpret_cast(data), size); + int32_t authType = *(reinterpret_cast(data)); + DmDeviceInfo deviceInfo; + std::string extraString(reinterpret_cast(data), size); + napi_env env; + std::shared_ptr authCallback = + std::make_shared(env, pkgName); + + DeviceManager::GetInstance().AuthenticateDevice(pkgName, + authType, deviceInfo, extraString, authCallback); +} + +void UnAuthenticateDeviceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string bundleName(reinterpret_cast(data), size); + std::string deviceId(reinterpret_cast(data), size); + + DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceId); +} + +void VerifyAuthenticationFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string bundleName(reinterpret_cast(data), size); + std::string authParam(reinterpret_cast(data), size); + napi_env env; + std::shared_ptr verifyCallback = + std::make_shared(env, bundleName); + + DeviceManager::GetInstance().VerifyAuthentication(bundleName, authParam, verifyCallback); +} + +void RegisterDeviceManagerFaCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string bundleName(reinterpret_cast(data), size); + std::string packageName(reinterpret_cast(data), size); + napi_env env; + auto callback = std::make_shared(env, bundleName); + + DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback); +} + +void UnRegisterDeviceManagerFaCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string packName(reinterpret_cast(data), size); + DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(packName); +} + +void GetFaParamFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string packName(reinterpret_cast(data), size); + DmAuthParam authParam; + + DeviceManager::GetInstance().GetFaParam(packName, authParam); +} + +void SetUserOperationFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + int32_t action = *(reinterpret_cast(data)); + + DeviceManager::GetInstance().SetUserOperation(pkgName, action); +} + +void GetUdidByNetworkIdFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string pkgName(reinterpret_cast(data), size); + std::string netWorkId(reinterpret_cast(data), size); + std::string udid(reinterpret_cast(data), size); + + DeviceManager::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); +} + +void GetUuidByNetworkIdFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string packName(reinterpret_cast(data), size); + std::string netWorkId(reinterpret_cast(data), size); + std::string uuid(reinterpret_cast(data), size); + + DeviceManager::GetInstance().GetUuidByNetworkId(packName, netWorkId, uuid); +} + +void RegisterDevStateCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string bundleName(reinterpret_cast(data), size); + napi_env env; + auto callback = std::make_shared(env, bundleName); + std::string extra(reinterpret_cast(data), size); + + int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, + extra, callback); + ret = DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitDeviceManagerFuzzTest(data, size); + OHOS::DistributedHardware::DeviceListFuzzTest(data, size); + OHOS::DistributedHardware::RegisterDevStateCallbackFuzzTest(data, size); + OHOS::DistributedHardware::DeviceDiscoveryFuzzTest(data, size); + OHOS::DistributedHardware::AuthenticateDeviceFuzzTest(data, size); + OHOS::DistributedHardware::UnAuthenticateDeviceFuzzTest(data, size); + OHOS::DistributedHardware::VerifyAuthenticationFuzzTest(data, size); + OHOS::DistributedHardware::RegisterDeviceManagerFaCallbackFuzzTest(data, size); + OHOS::DistributedHardware::UnRegisterDeviceManagerFaCallbackFuzzTest(data, size); + OHOS::DistributedHardware::GetFaParamFuzzTest(data, size); + OHOS::DistributedHardware::SetUserOperationFuzzTest(data, size); + OHOS::DistributedHardware::GetUdidByNetworkIdFuzzTest(data, size); + OHOS::DistributedHardware::GetUuidByNetworkIdFuzzTest(data, size); + + return 0; +} diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.h b/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2e4d1d838278e88631babab722819b8b84a0ff17 --- /dev/null +++ b/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_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 DEVICE_MANAGER_IMPL_FUZZER_H +#define DEVICE_MANAGER_IMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "devicemanagerimpl_fuzzer" + +#endif // DEVICE_MANAGER_IMPL_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/project.xml b/test/fuzztest/devicemanagerimpl_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/devicemanagerimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn b/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6e239e70d135a1446e9972363de4bcd3649ea2ce --- /dev/null +++ b/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn @@ -0,0 +1,102 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DeviceManagerNotifyFuzzTest") { + module_out_path = "devicemanager/devicemanagernotify_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/devicemanagernotify_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include", + "${services_path}/include/dependency/timer", + "${services_path}/include/discovery", + "${services_path}/include/dependency/softbus", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo/", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "device_manager_notify_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DeviceManagerNotifyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DeviceManagerNotifyFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/devicemanagernotify_fuzzer/corpus/init b/test/fuzztest/devicemanagernotify_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/devicemanagernotify_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/devicemanagernotify_fuzzer/device_manager_notify_fuzzer.cpp b/test/fuzztest/devicemanagernotify_fuzzer/device_manager_notify_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb45fa70e9a7566c28343df45ee08778d7636224 --- /dev/null +++ b/test/fuzztest/devicemanagernotify_fuzzer/device_manager_notify_fuzzer.cpp @@ -0,0 +1,96 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include "ipc_client_manager.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_rsp.h" +#include "ipc_def.h" +#include "device_manager_notify.h" +#include "dm_device_info.h" +#include "ipc_client_stub.h" +#include "ipc_register_listener_req.h" +#include "ipc_remote_broker.h" +#include "iremote_object.h" +#include "iservice_registry.h" +#include "dm_constants.h" +#include "system_ability_definition.h" +#include "device_manager_notify_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceManagerNotifyUnRegisterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + std::string deviceId(reinterpret_cast(data), size); + uint16_t subscribeId = *(reinterpret_cast(data)); + + DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(pkgName); + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName); + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName); + DeviceManagerNotify::GetInstance().UnRegisterVerifyAuthenticationCallback(pkgName); + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId); + DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId); + DeviceManagerNotify::GetInstance().OnFaCall(pkgName, deviceId); +} +void DeviceManagerNotifyDeviceStatusFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string pkgName(reinterpret_cast(data), size); + std::string deviceId(reinterpret_cast(data), size); + std::string authPara(reinterpret_cast(data), size); + std::string token(reinterpret_cast(data), size); + uint16_t subscribeId = *(reinterpret_cast(data)); + int32_t resultCode = *(reinterpret_cast(data)); + int32_t flag = *(reinterpret_cast(data)); + int32_t failedReason = *(reinterpret_cast(data)); + uint32_t status = *(reinterpret_cast(data)); + uint32_t reason = *(reinterpret_cast(data)); + DmDeviceInfo deviceInfo; + + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, deviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, deviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceInfo); + + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason); + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DeviceManagerNotifyUnRegisterFuzzTest(data, size); + OHOS::DistributedHardware::DeviceManagerNotifyDeviceStatusFuzzTest(data, size); + + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/devicemanagernotify_fuzzer/device_manager_notify_fuzzer.h b/test/fuzztest/devicemanagernotify_fuzzer/device_manager_notify_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..35bbace987f1b13df9ba28d394dfab8ec2cf2bf1 --- /dev/null +++ b/test/fuzztest/devicemanagernotify_fuzzer/device_manager_notify_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 DEVICE_MANAGER_NOTIFY_FUZZER_H +#define DEVICE_MANAGER_NOTIFY_FUZZER_H + +#define FUZZ_PROJECT_NAME "devicemanagernotify_fuzzer" + +#endif // DEVICE_MANAGER_NOTIFY_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/devicemanagernotify_fuzzer/project.xml b/test/fuzztest/devicemanagernotify_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/devicemanagernotify_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn b/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..486974013fcb0372ea3b0bbf02bf83ab296d9671 --- /dev/null +++ b/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn @@ -0,0 +1,102 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DeviceManagerServiceFuzzTest") { + module_out_path = "devicemanager/devicemanagerservice_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/devicemanagerservice_fuzzer" + + include_dirs = [ + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include", + "${services_path}/include/dependency/timer", + "${services_path}/include/discovery", + "${services_path}/include/dependency/softbus", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo/", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "device_manager_service_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DeviceManagerServiceFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DeviceManagerServiceFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/devicemanagerservice_fuzzer/corpus/init b/test/fuzztest/devicemanagerservice_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/devicemanagerservice_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/devicemanagerservice_fuzzer/device_manager_service_fuzzer.cpp b/test/fuzztest/devicemanagerservice_fuzzer/device_manager_service_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78bf587cdef0f1986e3b890c0970e7c5dda00592 --- /dev/null +++ b/test/fuzztest/devicemanagerservice_fuzzer/device_manager_service_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 +#include +#include "device_manager_service.h" +#include "device_manager_service_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceManagerServiceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + std::string extra(reinterpret_cast(data), size); + int32_t authType = *(reinterpret_cast(data)); + uint16_t subscribeId = *(reinterpret_cast(data)); + DmSubscribeInfo subscribeInfo; + std::vector deviceList; + DmDeviceInfo info; + DmAuthParam authParam; + + int32_t ret = DeviceManagerService::GetInstance().StartDeviceDiscovery(pkgName, subscribeInfo, extra); + ret = DeviceManagerService::GetInstance().GetLocalDeviceInfo(info); + ret = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList); + ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, pkgName, pkgName); + ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, pkgName, pkgName); + ret = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, pkgName, extra); + ret = DeviceManagerService::GetInstance().VerifyAuthentication(pkgName); + ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam); + ret = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, extra); + ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, authType); + ret = DeviceManagerService::GetInstance().RegisterDevStateCallback(pkgName, extra); + ret = DeviceManagerService::GetInstance().UnRegisterDevStateCallback(pkgName, extra); + ret = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DeviceManagerServiceFuzzTest(data, size); + + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/devicemanagerservice_fuzzer/device_manager_service_fuzzer.h b/test/fuzztest/devicemanagerservice_fuzzer/device_manager_service_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..346817263387763b878561f960254beadf364d8b --- /dev/null +++ b/test/fuzztest/devicemanagerservice_fuzzer/device_manager_service_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 DEVICE_MANAGER_SERVICE_FUZZER_H +#define DEVICE_MANAGER_SERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "devicemanagerservice_fuzzer" + +#endif // DEVICE_MANAGER_SERVICE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/devicemanagerservice_fuzzer/project.xml b/test/fuzztest/devicemanagerservice_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/devicemanagerservice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn b/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..babfb15394643a64258288a96306d4b92dcd3df5 --- /dev/null +++ b/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn @@ -0,0 +1,148 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("IpcClientManagerFuzzTest") { + module_out_path = "devicemanager/ipcclientmanager_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcclientmanager_fuzzer" + + include_dirs = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include/dependency/timer", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/json/include", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ipc_client_manager_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", + "//base/security/deviceauth/services:deviceauth_sdk", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"IpcClientManagerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + public_deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//utils/native/base:utils", + ] + +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":IpcClientManagerFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/ipcclientmanager_fuzzer/corpus/init b/test/fuzztest/ipcclientmanager_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/ipcclientmanager_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ipcclientmanager_fuzzer/ipc_client_manager_fuzzer.cpp b/test/fuzztest/ipcclientmanager_fuzzer/ipc_client_manager_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39bf2b41751d0e35e9f248c799a3369c1820d984 --- /dev/null +++ b/test/fuzztest/ipcclientmanager_fuzzer/ipc_client_manager_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include "ipc_client_manager.h" +#include "ipc_client_manager_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void IpcClientManagerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + int32_t cmdCode = *(reinterpret_cast(data)); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + + std::shared_ptr instance = std::make_shared(); + int32_t ret = instance->Init(pkgName); + ret = instance->UnInit(pkgName); + ret = instance->SendRequest(cmdCode, req, rsp); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::IpcClientManagerFuzzTest(data, size); + + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ipcclientmanager_fuzzer/ipc_client_manager_fuzzer.h b/test/fuzztest/ipcclientmanager_fuzzer/ipc_client_manager_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..46ab9c81cb103de4033ef50687127e959ddeba4b --- /dev/null +++ b/test/fuzztest/ipcclientmanager_fuzzer/ipc_client_manager_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 IPC_CLIENT_MANAGER_FUZZER_H +#define IPC_CLIENT_MANAGER_FUZZER_H + +#define FUZZ_PROJECT_NAME "ipcclientmanager_fuzzer" + +#endif // IPC_CLIENT_MANAGER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ipcclientmanager_fuzzer/project.xml b/test/fuzztest/ipcclientmanager_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/ipcclientmanager_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn b/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7db9431c16c6a50cea21c8e953246e1134f6badb --- /dev/null +++ b/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn @@ -0,0 +1,148 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("IpcCmdRegisterFuzzTest") { + module_out_path = "devicemanager/ipccmdregister_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipccmdregister_fuzzer" + + include_dirs = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include/dependency/timer", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/json/include", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice/include/ipc/lite", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ipc_cmd_register_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", + "//base/security/deviceauth/services:deviceauth_sdk", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"IpcCmdRegisterFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + public_deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":IpcCmdRegisterFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/ipccmdregister_fuzzer/corpus/init b/test/fuzztest/ipccmdregister_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/ipccmdregister_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp b/test/fuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b8fa8300c6efcae510fc3dcd5a3b2e946eecf6b9 --- /dev/null +++ b/test/fuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.cpp @@ -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. + */ +#include +#include +#include +#include +#include +#include "ipc_cmd_register.h" +#include "ipc_client_manager.h" +#include "ipc_register_listener_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_get_info_by_network_rsp.h" +#include "ipc_get_info_by_network_req.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_get_dmfaparam_rsp.h" +#include "ipc_register_dev_state_callback_req.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_verify_authenticate_req.h" +#include "ipc_unauthenticate_device_req.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_get_local_device_info_rsp.h" +#include "device_manager_notify.h" +#include "ipc_req.h" +#include "dm_device_info.h" +#include "dm_constants.h" +#include "ipc_def.h" +#include "dm_log.h" +#include "ipc_server_listenermgr.h" +#include "ipc_rsp.h" +#include "ipc_cmd_register_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void IpcCmdRegisterFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + int32_t cmdCode = *(reinterpret_cast(data)); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + MessageParcel data1; + MessageParcel reply1; + + int32_t ret = IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data1); + ret = IpcCmdRegister::GetInstance().ReadResponse(cmdCode, data1, rsp); + ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data1, reply1); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::IpcCmdRegisterFuzzTest(data, size); + + return 0; +} diff --git a/test/fuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.h b/test/fuzztest/ipccmdregister_fuzzer/ipc_cmd_register_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4e2e06d2b251debce2ac19ca0d0f0072acb3a7e6 --- /dev/null +++ b/test/fuzztest/ipccmdregister_fuzzer/ipc_cmd_register_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 IPC_CMD_REGISTER_FUZZER_H +#define IPC_CMD_REGISTER_FUZZER_H + +#define FUZZ_PROJECT_NAME "ipccmdregister_fuzzer" + +#endif // IPC_CMD_REGISTER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ipccmdregister_fuzzer/project.xml b/test/fuzztest/ipccmdregister_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/ipccmdregister_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn b/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5260fdbe08c3f120c90d9600ab215c77ceee51cf --- /dev/null +++ b/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn @@ -0,0 +1,147 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("IpcServerClientProxyFuzzTest") { + module_out_path = "devicemanager/ipcserverclientproxy_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcserverclientproxy_fuzzer" + + include_dirs = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include/dependency/timer", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/json/include", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ipc_server_client_proxy_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", + "//base/security/deviceauth/services:deviceauth_sdk", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"IpcServerClientProxyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + public_deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":IpcServerClientProxyFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/corpus/init b/test/fuzztest/ipcserverclientproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/ipcserverclientproxy_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp b/test/fuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fc4b171f257c7ad668fb2bb171209e7328e9935c --- /dev/null +++ b/test/fuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_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 +#include +#include +#include +#include +#include "ipc_server_client_proxy.h" +#include "ipc_server_client_proxy_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void IpcServerClientProxyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + int32_t cmdCode = *(reinterpret_cast(data)); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + sptr remoteObject = nullptr; + + auto instance = new IpcServerClientProxy(remoteObject); + if (instance != nullptr) { + instance->SendCmd(cmdCode, req, rsp); + delete instance; + } +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::IpcServerClientProxyFuzzTest(data, size); + + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.h b/test/fuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_proxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..05c7d3d6c698feb844bd2e836b8f3426504d4c31 --- /dev/null +++ b/test/fuzztest/ipcserverclientproxy_fuzzer/ipc_server_client_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 IPC_SERVER_CLIENT_PROXY_FUZZER_H +#define IPC_SERVER_CLIENT_PROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "ipcserverclientproxy_fuzzer" + +#endif // IPC_SERVER_CLIENT_PROXY_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/project.xml b/test/fuzztest/ipcserverclientproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/ipcserverclientproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn b/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..643eed1057f52b74cbbc893d45cfc2de15257f8c --- /dev/null +++ b/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn @@ -0,0 +1,147 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("IpcServerListenerFuzzTest") { + module_out_path = "devicemanager/ipcserverlistener_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcserverlistener_fuzzer" + + include_dirs = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include/dependency/timer", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/json/include", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ipc_server_listener_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", + "//base/security/deviceauth/services:deviceauth_sdk", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"IpcServerListenerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + public_deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":IpcServerListenerFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/ipcserverlistener_fuzzer/corpus/init b/test/fuzztest/ipcserverlistener_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/ipcserverlistener_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp b/test/fuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c4e8ff62be41c889722ca8eebeb4e5c429fc8900 --- /dev/null +++ b/test/fuzztest/ipcserverlistener_fuzzer/ipc_server_listener_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 +#include +#include +#include +#include +#include "ipc_server_listener.h" +#include "ipc_server_listener_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void IpcServerListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + int32_t cmdCode = *(reinterpret_cast(data)); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + + std::shared_ptr ipcServerListener = std::make_shared(); + int32_t ret = ipcServerListener->SendRequest(cmdCode, req, rsp); + ret = ipcServerListener->SendAll(cmdCode, req, rsp); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::IpcServerListenerFuzzTest(data, size); + + return 0; +} diff --git a/test/fuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.h b/test/fuzztest/ipcserverlistener_fuzzer/ipc_server_listener_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4c80252e8c5ef9d6b5384201e736d4375a1e37a5 --- /dev/null +++ b/test/fuzztest/ipcserverlistener_fuzzer/ipc_server_listener_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 IPC_SERVER_LISTENER_FUZZER_H +#define IPC_SERVER_LISTENER_FUZZER_H + +#define FUZZ_PROJECT_NAME "ipcserverlistener_fuzzer" + +#endif // IPC_SERVER_LISTENER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ipcserverlistener_fuzzer/project.xml b/test/fuzztest/ipcserverlistener_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/ipcserverlistener_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn b/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c92764a408e7801c0a63b24a6d6f6e500dcdb4b7 --- /dev/null +++ b/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn @@ -0,0 +1,147 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("IpcServerStubFuzzTest") { + module_out_path = "devicemanager/ipcserverstub_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcserverstub_fuzzer" + + include_dirs = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include/dependency/timer", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/json/include", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ipc_server_stub_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", + "//base/security/deviceauth/services:deviceauth_sdk", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"IpcServerStubFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + public_deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":IpcServerStubFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/ipcserverstub_fuzzer/corpus/init b/test/fuzztest/ipcserverstub_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/ipcserverstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp b/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b05ae5c91d2207c88062b544e57de1ae560ed484 --- /dev/null +++ b/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * 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 +#include +#include + +#include "ipc_client_stub.h" +#include "dm_device_info.h" +#include "ipc_server_stub.h" +#include "device_manager_impl.h" +#include "dm_constants.h" +#include "if_system_ability_manager.h" +#include "ipc_cmd_register.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iservice_registry.h" +#include "string_ex.h" +#include "system_ability_definition.h" +#include "ipc_server_stub_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void IpcServerStubFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + uint32_t code = *(reinterpret_cast(data)); + MessageParcel data1; + MessageParcel reply; + MessageOption option; + std::string pkgName(reinterpret_cast(data), size); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + sptr listener = data1.ReadRemoteObject(); + + int32_t ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option); + ret = IpcServerStub::GetInstance().SendCmd(code, req, rsp); + ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); + ret = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); + sptr ipcPtr = IpcServerStub::GetInstance().GetDmListener(pkgName); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::IpcServerStubFuzzTest(data, size); + + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.h b/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7d9f7876fecf453348dc75b1421f81e73a603c19 --- /dev/null +++ b/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_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 IPC_SERVER_STUB_FUZZER_H +#define IPC_SERVER_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "ipcserverstub_fuzzer" + +#endif // IPC_SERVER_STUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ipcserverstub_fuzzer/project.xml b/test/fuzztest/ipcserverstub_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/ipcserverstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/BUILD.gn b/test/fuzztest/nativedevicemanagerjs_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fed59ca7538f6e4989ba65f7c75052b780c9bdbb --- /dev/null +++ b/test/fuzztest/nativedevicemanagerjs_fuzzer/BUILD.gn @@ -0,0 +1,147 @@ +# 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/devicemanager/devicemanager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("NativeDevicemanagerJsFuzzTest") { + module_out_path = "devicemanager/nativedevicemanagerjs_fuzzer" + fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/nativedevicemanagerjs_fuzzer" + + include_dirs = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", + "//third_party/node/src", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "//third_party/json/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include/dependency/timer", + "${services_path}/include/dependency/softbus", + "${services_path}/include/authentication", + "${services_path}/include/adapter", + "${services_path}/include", + "${services_path}/include/ipc/standard", + "${services_path}/include/discovery", + "${services_path}/include/dependency/hichain", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/softbus_lite/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + "//foundation/distributedhardware/devicemanager/test/unittest/mock", + "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", + "//base/security/deviceauth/interfaces/innerkits", + "${services_path}/include/ability", + "${services_path}/include/config", + "//utils/native/lite/include", + "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", + "//third_party/bounds_checking_function/include", + "//foundation/communication/ipc_lite/interfaces/kits", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", + "//third_party/json/include", + "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", + "//foundation/ace/napi/interfaces/innerkits/napi", + "//foundation/ace/napi/interfaces/innerkits", + "//third_party/jsframework/runtime/main/extend", + "//foundation/windowmanager/interfaces/kits", + "//third_party/jsframework/runtime/main/extend/systemplugin", + "//third_party/node/benchmark", + "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", + "//third_party/libuv/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "native_devicemanager_js_fuzzer.cpp" ] + + deps = [ + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", + "//base/security/deviceauth/services:deviceauth_sdk", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/aafwk/standard/services/abilitymgr:abilityms", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"NativeDevicemanagerJsFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "ipc:ipc_core", + "samgr_standard:samgr_proxy", + "startup_l2:syspara", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + public_deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${utils_path}:devicemanagerutils", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest", + "//utils/native/base:utils", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":NativeDevicemanagerJsFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/corpus/init b/test/fuzztest/nativedevicemanagerjs_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..59aefb51c6e5a670d20c9bda3030fcdf8db29e5a --- /dev/null +++ b/test/fuzztest/nativedevicemanagerjs_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-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. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.cpp b/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9ac34f9259548c453087f94820e471e4cc697f6 --- /dev/null +++ b/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.cpp @@ -0,0 +1,95 @@ +/* + * 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 +#include "native_devicemanager_js.h" +#include "device_manager.h" +#include "dm_constants.h" +#include "dm_log.h" +#include "device_manager_callback.h" +#include "dm_app_image_info.h" +#include "dm_device_info.h" +#include "dm_native_event.h" +#include "dm_subscribe_info.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "nlohmann/json.hpp" +#include "native_devicemanager_js_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void NativeDeviceManagerStaticFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + napi_env env = *(reinterpret_cast(data)); + napi_callback_info info = *(reinterpret_cast(data)); + std::string buldleName(reinterpret_cast(data), size); + DeviceManagerNapi *deviceManagerNapiPtr = DeviceManagerNapi::GetDeviceManagerNapi(buldleName); + if (deviceManagerNapiPtr == nullptr) { + return; + } + + napi_value result = deviceManagerNapiPtr->CreateDeviceManager(env, info); + result = deviceManagerNapiPtr->GetTrustedDeviceListSync(env, info); + result = deviceManagerNapiPtr->AuthenticateDevice(env, info); + result = deviceManagerNapiPtr->VerifyAuthInfo(env, info); + result = deviceManagerNapiPtr->JsOn(env, info); + result = deviceManagerNapiPtr->JsOff(env, info); + result = deviceManagerNapiPtr->ReleaseDeviceManager(env, info); +} + +void NativeDeviceManagerOnFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + std::string buldleName(reinterpret_cast(data), size); + std::string token(reinterpret_cast(data), size); + int32_t reason = *(reinterpret_cast(data)); + uint16_t subscribeId = *(reinterpret_cast(data)); + DmNapiDevStateChangeAction action = *(reinterpret_cast(data)); + DmDeviceInfo deviceInfo = *(reinterpret_cast(data)); + + uv_work_t *work = new (std::nothrow) uv_work_t; + std::unique_ptr jsCallback_; + jsCallback_ = std::make_unique(buldleName, 0, 0, deviceInfo); + work->data = reinterpret_cast(jsCallback_.get()); + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + delete work; + + DeviceManagerNapi *deviceManagerNapiPtr = DeviceManagerNapi::GetDeviceManagerNapi(buldleName); + if (deviceManagerNapiPtr == nullptr) { + return; + } + deviceManagerNapiPtr->OnDeviceStateChange(action, callback->deviceInfo_); + deviceManagerNapiPtr->OnDeviceFound(subscribeId, callback->deviceInfo_); + deviceManagerNapiPtr->OnDiscoveryFailed(subscribeId, reason); + deviceManagerNapiPtr->OnAuthResult(buldleName, token, reason, reason); + deviceManagerNapiPtr->OnVerifyResult(buldleName, reason, reason); + deviceManagerNapiPtr->OnDmfaCall(buldleName); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::NativeDeviceManagerStaticFuzzTest(data, size); + OHOS::DistributedHardware::NativeDeviceManagerOnFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.h b/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..89ec6f7ed3986065e56183290471b2c31d147c02 --- /dev/null +++ b/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_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 NATIVE_DEVICEMANAGER_JS_FUZZER_H +#define NATIVE_DEVICEMANAGER_JS_FUZZER_H + +#define FUZZ_PROJECT_NAME "nativedevicemanagerjs_fuzzer" + +#endif // NATIVE_DEVICEMANAGER_JS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/project.xml b/test/fuzztest/nativedevicemanagerjs_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d --- /dev/null +++ b/test/fuzztest/nativedevicemanagerjs_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file