diff --git a/test/BUILD.gn b/test/BUILD.gn index c856a29d07410f6762367b2c15713fd527d77ca9..e5cb6fa45c39bd07b060a512b7a0f3de40896eb8 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -1,28 +1,28 @@ -# Copyright (c) 2022-2023 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("test") { - testonly = true - - deps = [] - if (support_jsapi) { - deps += [ - "benchmarktest:benchmarktest", - "commonfuzztest:fuzztest", - "interfacesfuzztest:fuzztest", - "servicesfuzztest:fuzztest", - "softbusfuzztest:fuzztest", - "unittest:unittest", - ] - } -} +# Copyright (c) 2022-2025 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("test") { + testonly = true + + deps = [] + if (support_jsapi) { + deps += [ + "benchmarktest:benchmarktest", + "commonfuzztest:fuzztest", + "interfacesfuzztest:fuzztest", + "servicesfuzztest:fuzztest", + "softbusfuzztest:fuzztest", + "unittest:unittest", + ] + } +} diff --git a/test/commonfuzztest/BUILD.gn b/test/commonfuzztest/BUILD.gn index c88c67ba243daa0e32af9e3f00ab22ec24c2da27..72dc45f2b20620d4dbd209dabedbeb9aa7be0316 100644 --- a/test/commonfuzztest/BUILD.gn +++ b/test/commonfuzztest/BUILD.gn @@ -15,13 +15,15 @@ group("fuzztest") { testonly = true deps = [ + "authacl_fuzzer:fuzztest", + "authcredential_fuzzer:fuzztest", "authenticatedevice_fuzzer:fuzztest", "authenticatedeviceservice_fuzzer:fuzztest", "authenticatedeviceserviceimpl_fuzzer:fuzztest", - "dmauthmanager_fuzzer:fuzztest", - "dmauthmanagerv2_fuzzer:fuzztest", + "dmanonyous_fuzzer:fuzztest", "dmcommoneventmanager_fuzzer:fuzztest", "dmcredentialimpl_fuzzer:fuzztest", + "dmfreezeprocess_fuzzer:fuzztest", "generateencrypteduuid_fuzzer:fuzztest", "getdeviceinfo_fuzzer:fuzztest", "hichainconnector_fuzzer:fuzztest", @@ -33,5 +35,6 @@ group("fuzztest") { "pinauth_fuzzer:fuzztest", "pinauthui_fuzzer:fuzztest", "pinholder_fuzzer:fuzztest", + ] } diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn b/test/commonfuzztest/authacl_fuzzer/BUILD.gn similarity index 84% rename from test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn rename to test/commonfuzztest/authacl_fuzzer/BUILD.gn index fb2de39cab0aa6a70aefea49cc690e3e5d00b8f4..9b8b4567149e08d1a72a78c69c20c8bfbaf4f56d 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authacl_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 @@ -17,10 +17,10 @@ import("//build/test.gni") import("//foundation/distributedhardware/device_manager/device_manager.gni") ##############################fuzztest########################################## -ohos_fuzztest("DmAuthManagerV2FuzzTest") { +ohos_fuzztest("AuthAclFuzzTest") { module_out_path = fuzz_test_output_path fuzz_config_file = - "${devicemanager_path}/test/commonfuzztest/dmauthmanagerv2_fuzzer" + "${devicemanager_path}/test/commonfuzztest/authacl_fuzzer" include_dirs = [ "${innerkits_path}/native_cpp/include", @@ -42,13 +42,13 @@ ohos_fuzztest("DmAuthManagerV2FuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dm_auth_manager_fuzzer.cpp" ] + sources = [ "auth_acl_fuzzer.cpp" ] deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", - "${services_path}:devicemanagerservice", + "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] external_deps = [ @@ -66,15 +66,17 @@ ohos_fuzztest("DmAuthManagerV2FuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DmAuthManagerV2FuzzTest\"", + "DH_LOG_TAG=\"AuthAclFuzzTest\"", "LOG_DOMAIN=0xD004110", ] + cflags_cc=[ "--coverage"] + ldflags = ["--coverage"] } ############################################################################### group("fuzztest") { testonly = true - deps = [ ":DmAuthManagerV2FuzzTest" ] + deps = [ ":AuthAclFuzzTest" ] } ############################################################################### diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..327347467443f73f08d787eefee99ca9c8c0f75b --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025-2025 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 "auth_acl_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_auth_state.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +void AuthAclFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(); + std::shared_ptr authSink = std::make_shared(); + std::shared_ptr authSrc = std::make_shared(); + + authSink->GetStateType(); + authSrc->GetStateType(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::AuthAclFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.h b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h similarity index 80% rename from test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.h rename to test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h index 35643d1c413a5faa1d10d0d6c7812892ccdc835f..6e30090a78af52782e611ce889b13336f8a51412 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.h +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef DM_AUTH_MANAGER_FUZZER_H -#define DM_AUTH_MANAGER_FUZZER_H +#ifndef AUTH_ACL_FUZZER_H +#define AUTH_ACL_FUZZER_H -#define FUZZ_PROJECT_NAME "dmauthmanagerv2_fuzzer" +#define FUZZ_PROJECT_NAME "authacl_fuzzer" -#endif // DM_AUTH_MANAGER_FUZZER_H \ No newline at end of file +#endif // AUTH_ACL_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/corpus/init b/test/commonfuzztest/authacl_fuzzer/corpus/init similarity index 92% rename from test/commonfuzztest/dmauthmanagerv2_fuzzer/corpus/init rename to test/commonfuzztest/authacl_fuzzer/corpus/init index d9719cafab50ed61d354cfa865b56390a0df320f..8f37f09254457133cae0f828d0a5faee7dcbd779 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/corpus/init +++ b/test/commonfuzztest/authacl_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/project.xml b/test/commonfuzztest/authacl_fuzzer/project.xml similarity index 95% rename from test/commonfuzztest/dmauthmanagerv2_fuzzer/project.xml rename to test/commonfuzztest/authacl_fuzzer/project.xml index bac4974e9068af3c045fbb5c3a588aa79e47faaf..500f6f414493290025d8dea9b066e5d5021a9377 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/project.xml +++ b/test/commonfuzztest/authacl_fuzzer/project.xml @@ -1,5 +1,5 @@ - + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp b/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp deleted file mode 100644 index 053f739b42d242982e690c910b6a7f0c3c959635..0000000000000000000000000000000000000000 --- a/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2023-2024 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_listener.h" -#include "auth_message_processor.h" -#include "dm_auth_manager.h" -#include "dm_auth_manager_fuzzer.h" -#include "dm_timer.h" -#include "hichain_connector.h" - -namespace OHOS { -namespace DistributedHardware { - -std::shared_ptr g_softbusConnector = std::make_shared(); -std::shared_ptr g_listener = std::make_shared(); -std::shared_ptr g_hiChainConnector = std::make_shared(); -std::shared_ptr g_hiChainAuthConnector = std::make_shared(); -std::shared_ptr g_authRequestState = std::make_shared(); -std::shared_ptr g_authResponseState = std::make_shared(); -std::shared_ptr g_authManager = - std::make_shared(g_softbusConnector, g_hiChainConnector, g_listener, g_hiChainAuthConnector); - -int32_t g_sessionId = 1; -int32_t g_sessionSide = 0; -int32_t g_result = 1; -int32_t g_authType = 1; -int32_t g_status = 1; -std::string g_pinCode = "111111"; -int32_t g_action = 1; -int32_t g_userId = 1; -int32_t g_pageId = 1; -int32_t g_reason = 1; -int32_t g_state = 1; -int64_t g_requestId = 1; -int64_t g_localSessionId = 1; - -std::map g_bindParam; - -PeerTargetId g_targetId = { - .deviceId = "deviceId", - .brMac = "brMac", - .bleMac = "bleMac", - .wifiIp = "wifiIp", -}; - -void DmAuthManagerFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string str(reinterpret_cast(data), size); - int32_t bindLevel = fdp.ConsumeIntegral(); - g_authManager->authMessageProcessor_ = std::make_shared(g_authManager); - g_authManager->authMessageProcessor_->authResponseContext_ = std::make_shared(); - g_authManager->authRequestContext_ = std::make_shared(); - g_authManager->authRequestState_ = std::make_shared(); - g_authManager->authResponseContext_ = std::make_shared(); - g_authManager->authResponseState_ = std::make_shared(); - g_authManager->hiChainAuthConnector_ = std::make_shared(); - g_authManager->softbusConnector_ = std::make_shared(); - g_authManager->softbusConnector_->GetSoftbusSession()-> - RegisterSessionCallback(std::shared_ptr(g_authManager)); - g_authManager->timer_ = std::make_shared(); - - g_authManager->InitAuthState(str, g_authType, str, str); - g_authManager->OnSessionOpened(g_sessionId, g_sessionSide, g_result); - g_authManager->AuthenticateDevice(str, g_authType, str, str); - g_authManager->ImportAuthCode(str, str); - g_authManager->BindTarget(str, g_targetId, g_bindParam, g_sessionId, g_localSessionId); - g_authManager->ShowConfigDialog(); - g_authManager->ShowAuthInfoDialog(); - g_authManager->ShowStartAuthDialog(); - g_authManager->OnDataReceived(g_sessionId, str); - g_authManager->OnGroupCreated(g_requestId, str); - g_authManager->OnMemberJoin(g_requestId, g_status); - g_authManager->StartNegotiate(g_sessionId); - g_authManager->RespNegotiate(g_sessionId); - g_authManager->SendAuthRequest(g_sessionId); - g_authManager->SetAuthRequestState(g_authRequestState); - g_authManager->SetAuthResponseState(g_authResponseState); - g_authManager->StartAuthProcess(g_action); - g_authManager->StartRespAuthProcess(); - g_authManager->CreateGroup(); - g_authManager->ProcessPincode(g_pinCode); - g_authManager->SetPageId(g_pageId); - g_authManager->SetReasonAndFinish(g_reason, g_state); - g_authManager->IsIdenticalAccount(); - g_authManager->OnSessionClosed(g_sessionId); - g_authManager->OnUserOperation(g_action, str); - g_authManager->GetConnectAddr(str); - g_authManager->HandleAuthenticateTimeout(str); - g_authManager->RegisterUiStateCallback(str); - g_authManager->UnRegisterUiStateCallback(str); - g_authManager->UnAuthenticateDevice(str, str, bindLevel); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DmAuthManagerFuzzTest(data, size); - - return 0; -} \ No newline at end of file diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp b/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp deleted file mode 100644 index 018ed36976c6e991705bdcd72676cc909fda175b..0000000000000000000000000000000000000000 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/dm_auth_manager_fuzzer.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2025-2025 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_listener.h" -#include "auth_manager.h" -#include "dm_auth_manager_fuzzer.h" - -namespace OHOS { -namespace DistributedHardware { - -int32_t g_sessionId = 1; -int32_t g_sessionSide = 0; -int32_t g_result = 1; -int32_t g_authType = 1; -int32_t g_status = 1; -int32_t g_pinCode = 1; -int32_t g_action = 1; -int32_t g_userId = 1; -int32_t g_pageId = 1; -int32_t g_reason = 1; -int32_t g_state = 1; -int64_t g_requestId = 1; -int64_t g_operationCode = 1; -int64_t g_localSessionId = 1; - -std::map g_bindParam; - -PeerTargetId g_targetId = { - .deviceId = "deviceId", - .brMac = "brMac", - .bleMac = "bleMac", - .wifiIp = "wifiIp", -}; - -// AuthSrcManager fuzz -void DmAuthSrcManagerFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr hiChainAuthConnector = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - FuzzedDataProvider fdp(data, size); - std::string str(reinterpret_cast(data), size); - int32_t bindLevel = fdp.ConsumeIntegral(); - std::shared_ptr authManager = std::make_shared(softbusConnector, hiChainConnector, - listener, hiChainAuthConnector); - - authManager->OnUserOperation(g_action, str); - authManager->BindTarget(str, g_targetId, g_bindParam, g_sessionId, g_localSessionId); - authManager->StopAuthenticateDevice(str); - authManager->ImportAuthCode(str, str); - authManager->RegisterUiStateCallback(str); - authManager->UnRegisterUiStateCallback(str); - authManager->UnAuthenticateDevice(str, str, bindLevel); - authManager->UnBindDevice(str, str, bindLevel, str); - authManager->HandleDeviceNotTrust(str); - authManager->DeleteGroup(str, str); - authManager->AuthDeviceTransmit(g_requestId, data, size); - authManager->AuthDeviceSessionKey(g_requestId, data, size); - authManager->AuthDeviceRequest(g_requestId, g_operationCode, str.c_str()); - authManager->OnDataReceived(g_sessionId, str); - authManager->OnAuthDeviceDataReceived(g_sessionId, str); -} - -// AuthSinkManager fuzz -void DmAuthSinkManagerFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - std::shared_ptr softbusConnector = std::make_shared(); - std::shared_ptr listener = std::make_shared(); - std::shared_ptr hiChainAuthConnector = std::make_shared(); - std::shared_ptr hiChainConnector = std::make_shared(); - FuzzedDataProvider fdp(data, size); - std::string str(reinterpret_cast(data), size); - int32_t bindLevel = fdp.ConsumeIntegral(); - std::shared_ptr authManager = std::make_shared(softbusConnector, hiChainConnector, - listener, hiChainAuthConnector); - - authManager->OnUserOperation(g_action, str); - authManager->BindTarget(str, g_targetId, g_bindParam, g_sessionId, g_localSessionId); - authManager->StopAuthenticateDevice(str); - authManager->ImportAuthCode(str, str); - authManager->RegisterUiStateCallback(str); - authManager->UnRegisterUiStateCallback(str); - authManager->UnAuthenticateDevice(str, str, bindLevel); - authManager->UnBindDevice(str, str, bindLevel, str); - authManager->HandleDeviceNotTrust(str); - authManager->DeleteGroup(str, str); - authManager->AuthDeviceTransmit(g_requestId, data, size); - authManager->AuthDeviceSessionKey(g_requestId, data, size); - authManager->AuthDeviceRequest(g_requestId, g_operationCode, str.c_str()); - authManager->OnDataReceived(g_sessionId, str); - authManager->OnAuthDeviceDataReceived(g_sessionId, str); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::DmAuthSrcManagerFuzzTest(data, size); - OHOS::DistributedHardware::DmAuthSinkManagerFuzzTest(data, size); - return 0; -} \ No newline at end of file diff --git a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn similarity index 85% rename from test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn rename to test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn index 1d394b8ad08031b12cdae65d7a128a8067ab2620..01ef24d272ca6803d48870076ae9785cf7196113 100644 --- a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 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 @@ -17,16 +17,16 @@ import("//build/test.gni") import("//foundation/distributedhardware/device_manager/device_manager.gni") ##############################fuzztest########################################## -ohos_fuzztest("DmAuthManagerFuzzTest") { +ohos_fuzztest("DmFreezeProcessFuzzTest") { module_out_path = fuzz_test_output_path fuzz_config_file = - "${devicemanager_path}/test/commonfuzztest/dmauthmanager_fuzzer" + "${devicemanager_path}/test/commonfuzztest/dmfreezeprocess_fuzzer" include_dirs = [ "${innerkits_path}/native_cpp/include", "${servicesimpl_path}/include/ability", "${servicesimpl_path}/include/adapter", - "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/authentication_v2", "${servicesimpl_path}/include/dependency/hichain", "${servicesimpl_path}/include/dependency/softbus", "${servicesimpl_path}/include/dependency/timer", @@ -42,7 +42,7 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dm_auth_manager_fuzzer.cpp" ] + sources = [ "dm_freeze_process_fuzzer.cpp" ] deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", @@ -52,6 +52,7 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { ] external_deps = [ + "cJSON:cjson", "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", @@ -65,7 +66,7 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DmAuthManagerFuzzTest\"", + "DH_LOG_TAG=\"DmFreezeProcessFuzzTest\"", "LOG_DOMAIN=0xD004110", ] } @@ -74,6 +75,6 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { group("fuzztest") { testonly = true - deps = [ ":DmAuthManagerFuzzTest" ] + deps = [ ":DmFreezeProcessFuzzTest" ] } ############################################################################### diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init b/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8f37f09254457133cae0f828d0a5faee7dcbd779 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 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/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4c2c902eb03d195f1efd24f8f2fe686bbbec7b7 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025-2025 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 "dm_freeze_process_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { +constexpr const char* BIND_FAILED_EVENTS_KEY = "bindFailedEvents"; +constexpr const char* FREEZE_STATE_KEY = "freezeState"; +constexpr const char* START_FREEZE_TIME_KEY = "startFreezeTimeStamp"; +constexpr const char* STOP_FREEZE_TIME_KEY = "stopFreezeTimeStamp"; +constexpr const char* FAILED_TIMES_STAMPS_KEY = "failedTimeStamps"; +constexpr const char* FREEZE_TIMES_STAMPS_KEY = "freezeTimeStamps"; +constexpr const char* CAST_BUNDLE_NAME = "cast_engine_service"; +constexpr int32_t MAX_CONTINUEOUS_BIND_FAILED_NUM = 2; +constexpr int64_t CONTINUEOUS_FAILED_INTERVAL = 6 * 60; +constexpr int64_t DATA_REFRESH_INTERVAL = 20 * 60; +constexpr int64_t NOT_FREEZE_TIME = 0; +constexpr int64_t FIRST_FREEZE_TIME = 60; +constexpr int64_t SECOND_FREEZE_TIME = 3 * 60; +constexpr int64_t THIRD_FREEZE_TIME = 5 * 60; +constexpr int64_t MAX_FREEZE_TIME = 10 * 60; +} // namespace + +void DmFreezeProcessFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(); + DeviceFreezeState freezeStateObj; + BindFailedEvents bindFailedEvents; + std::string bundleName = CAST_BUNDLE_NAME; + int32_t deviceType = DEVICE_TYPE_TV; + int64_t reservedDataTimeStamp = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().ConvertJsonToDeviceFreezeState(result, freezeStateObj); + FreezeProcess::GetInstance().ConvertJsonToBindFailedEvents(result, bindFailedEvents); + bundleName = fdp.ConsumeRandomLengthString(); + deviceType = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().CleanBindFailedEvents(reservedDataTimeStamp); + FreezeProcess::GetInstance().CleanFreezeState(reservedDataTimeStamp); + FreezeProcess::GetInstance().ConvertDeviceFreezeStateToJson(freezeStateObj, result); + int64_t nowTime = NOT_FREEZE_TIME; + + int64_t nextTime = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().CleanFreezeRecord(nowTime); + FreezeProcess::GetInstance().UpdateFreezeState(nowTime); + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = FIRST_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = SECOND_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = MAX_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + FreezeProcess::GetInstance().DeleteFreezeRecord(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmFreezeProcessFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0628940ed1a9f8ec66d9f542b2ed03006d77208b --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 DM_FREE_PROCESS_FUZZER_H +#define DM_FREE_PROCESS_FUZZER_H + +#define FUZZ_PROJECT_NAME "dmfreezeprocess_fuzzer" + +#endif // DM_FREE_PROCESS_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml b/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonunittest/UTTest_hichain_connector.cpp b/test/commonunittest/UTTest_hichain_connector.cpp old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/BUILD.gn b/test/interfacesfuzztest/BUILD.gn old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn old mode 100755 new mode 100644 index a706fd85fd9b3811cc8d806586ca0ac77e5abd67..a7e9c70382236ee1d7ae696f97438bb8ea36608b --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn @@ -63,7 +63,7 @@ ohos_fuzztest("DeviceManagerImplFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] defines = [ diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/corpus/init b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/corpus/init old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp old mode 100755 new mode 100644 index 69cebe8cfdf924f777e0d2092c2be64143daae33..a42e4514577d312ed45213ae09d403e627c36cd7 --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp @@ -13,253 +13,282 @@ * limitations under the License. */ - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include - #include "device_manager_impl.h" - - namespace OHOS { - namespace DistributedHardware { - - namespace { - - } - - void StopAuthenticateDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); - DeviceManagerImpl::GetInstance().OnDmServiceDied(); - } - - void UnBindDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); - } - - void ShiftLNNGearTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); - } - - void RegDevTrustChangeCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::shared_ptr callback = nullptr; - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); - } - - void GetNetworkIdByUdidTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string udid = fdp.ConsumeRandomLengthString(); - std::string networkId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); - } - - void RegisterCredentialAuthStatusCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); - } - - void GetAllTrustedDeviceListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string extra = fdp.ConsumeRandomLengthString(); - std::vector deviceList; - DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); - } - - void RegisterSinkBindCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); - } - - void GetDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void GetDeviceIconInfoTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void PutDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::vector deviceProfileInfoList; - DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); - } - - void GetLocalDisplayDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string displayName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); - } - - void GetDeviceNetworkIdListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - NetworkIdQueryFilter queryFilter; - std::vector networkIds; - DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); - } - - void SetLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); - } - - void SetRemoteDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); - } - - void RestoreLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); - } - - void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DMLocalServiceInfo info; - DeviceManagerImpl::GetInstance(). - GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); - } - - void UnRegisterPinHolderCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); - } - } - } +#include "device_manager_impl.h" + +namespace OHOS { +namespace DistributedHardware { - /* Fuzzer entry point */ - extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) - { - /* Run your code on data */ - OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); - OHOS::DistributedHardware::UnBindDeviceTest(data, size); - OHOS::DistributedHardware::ShiftLNNGearTest(data, size); - OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); - OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); - OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); - OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); - OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); - OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); - OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); - OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); - OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); - OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); - OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); - return 0; - } - \ No newline at end of file +namespace {} + +void StopAuthenticateDeviceTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); + DeviceManagerImpl::GetInstance().OnDmServiceDied(); +} + +void UnBindDeviceTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); +} + +void ShiftLNNGearTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); +} + +void RegDevTrustChangeCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr callback = nullptr; + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); +} + +void GetNetworkIdByUdidTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string udid = fdp.ConsumeRandomLengthString(); + std::string networkId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); +} + +void RegisterCredentialAuthStatusCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); +} + +void GetAllTrustedDeviceListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::vector deviceList; + DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); +} + +void RegisterSinkBindCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); +} + +void GetDeviceProfileInfoListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void GetDeviceIconInfoTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void PutDeviceProfileInfoListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::vector deviceProfileInfoList; + DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); +} + +void GetLocalDisplayDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string displayName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); +} + +void GetDeviceNetworkIdListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + NetworkIdQueryFilter queryFilter; + std::vector networkIds; + DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); +} + +void SetLocalDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); +} + +void SetRemoteDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); +} + +void RestoreLocalDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); +} + +void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DMLocalServiceInfo info; + DeviceManagerImpl::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); +} + +void UnRegisterPinHolderCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); +} + +void DeviceManagerImplFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t pinExchangeType = fdp.ConsumeIntegral(); + OHOS::DistributedHardware::DmDeviceIconInfoFilterOptions filterOptions; + DMLocalServiceInfo localServiceInfo; + DmAccessCaller caller; + DmAccessCallee callee; + DMIpcCmdInterfaceCode ipcCode = REGISTER_DEVICE_MANAGER_LISTENER; + DeviceManagerImpl::GetInstance().GetLocalDeviceName(pkgName, deviceName); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId, extra); + DeviceManagerImpl::GetInstance().UnRegisterSinkBindCallback(pkgName); + DeviceManagerImpl::GetInstance().RegisterLocalServiceInfo(localServiceInfo); + DeviceManagerImpl::GetInstance().UnRegisterLocalServiceInfo(bundleName, pinExchangeType); + DeviceManagerImpl::GetInstance().UpdateLocalServiceInfo(localServiceInfo); + DeviceManagerImpl::GetInstance().CheckAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckSrcAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckSinkAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckSrcIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckSinkIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckAclByIpcCode(caller, callee, ipcCode); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); + OHOS::DistributedHardware::UnBindDeviceTest(data, size); + OHOS::DistributedHardware::ShiftLNNGearTest(data, size); + OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); + OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); + OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); + OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); + OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); + OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); + OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); + OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); + OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); + OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); + OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); + OHOS::DistributedHardware::DeviceManagerImplFuzzTest(data, size); + return 0; +} diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.h b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.h old mode 100755 new mode 100644 diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/project.xml b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/project.xml old mode 100755 new mode 100644 diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 074d1cd33715a9f81bbaddd058e4493560e36ee3..e6a972d7f23f1b823e1fd87fa3308e49dc573888 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -28,6 +28,7 @@ group("fuzztest") { "devicenamemanagerone_fuzzer:fuzztest", "deviceprofileconnector_fuzzer:fuzztest", "devicepublish_fuzzer:fuzztest", + "dmauthattestcommon_fuzzer:fuzztest", "dmcommtool_fuzzer:fuzztest", "dmcommtooltwo_fuzzer:fuzztest", "dmtransport_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp b/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp index 73a030896499aef157bc126129a446879c062779..679739aedb22b4b97ec802892e62a4af6f908dc4 100644 --- a/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp +++ b/test/servicesfuzztest/authmessageprocessor_fuzzer/auth_message_processor_fuzzer.cpp @@ -151,7 +151,86 @@ void AuthMessageProcessorFuzzTest(const uint8_t* data, size_t size) dmAuthMessageProcessor_ -> SetLnnAccessControlList(context_, accesser, accessee); AuthMessageProcessorFuzzTestNext(jsonObject); } + +void AuthMessageProcessorFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string message = fdp.ConsumeRandomLengthString(); + std::string inputStr = fdp.ConsumeRandomLengthString(); + std::string compressed = fdp.ConsumeRandomLengthString(); + std::string trustDeviceId = fdp.ConsumeRandomLengthString(); + std::string encSyncMsg = fdp.ConsumeRandomLengthString(); + std::string enSyncMsg = fdp.ConsumeRandomLengthString(); + std::string aclStr = fdp.ConsumeRandomLengthString(); + uint32_t keyLen = fdp.ConsumeIntegralInRange(0, 1024); + uint32_t oriLen = fdp.ConsumeIntegralInRange(0, 1024); + std::vector sessionKey = fdp.ConsumeBytes(keyLen); + int32_t userId = fdp.ConsumeIntegral(); + int32_t skId = fdp.ConsumeIntegral(); + DistributedDeviceProfile::AccessControlProfile acl; + DistributedDeviceProfile::Accesser accesser; + DistributedDeviceProfile::Accessee accessee; + acl.SetExtraData(fdp.ConsumeRandomLengthString()); + accesser.SetAccesserExtraData(fdp.ConsumeRandomLengthString()); + accessee.SetAccesseeExtraData(fdp.ConsumeRandomLengthString()); + DmAccess access; + JsonObject jsonObject; + GenerateJsonObject(jsonObject, fdp); + dmAuthMessageProcessor_->CheckLogicalSessionId(jsonObject, context_); + jsonObject[TAG_TRANSMIT_SK_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_TRANSMIT_SK_TIMESTAMP] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_TRANSMIT_CREDENTIAL_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_DMVERSION] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_LNN_SK_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_LNN_SK_TIMESTAMP] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_LNN_CREDENTIAL_ID] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_ACCESS] = fdp.ConsumeRandomLengthString(); + // Run ParseDmAccessToSync + dmAuthMessageProcessor_->ParseSyncMessage(context_, access, jsonObject); + jsonObject[TAG_AUTH_TYPE_LIST] = fdp.ConsumeRandomLengthString(); + jsonObject[TAG_EXTRA_INFO] = fdp.ConsumeRandomLengthString(); + // Run stringToVectorAuthType + dmAuthMessageProcessor_->ParseMessageRespUserConfirm(jsonObject, context_); } + +void AuthMessageProcessorSecondFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + JsonItemObject jsonItemObject; + DmAccessToSync sync_table = { .deviceName = fdp.ConsumeRandomLengthString(), + .deviceNameFull = fdp.ConsumeRandomLengthString(), + .deviceId = fdp.ConsumeRandomLengthString(), + .userId = fdp.ConsumeIntegral(), + .accountId = fdp.ConsumeRandomLengthString(), + .tokenId = fdp.ConsumeIntegral(), + .bundleName = fdp.ConsumeRandomLengthString(), + .pkgName = fdp.ConsumeRandomLengthString(), + .bindLevel = fdp.ConsumeIntegral(), + .sessionKeyId = fdp.ConsumeIntegral(), + .skTimeStamp = fdp.ConsumeIntegral() }; + FromJson(jsonItemObject, sync_table); + DmAccessControlTable control_table = { .accessControlId = fdp.ConsumeIntegral(), + .accesserId = fdp.ConsumeIntegral(), + .accesseeId = fdp.ConsumeIntegral(), + .deviceId = fdp.ConsumeRandomLengthString(), + .sessionKey = fdp.ConsumeRandomLengthString(), + .bindType = fdp.ConsumeIntegral(), + .authType = fdp.ConsumeIntegral(), + .deviceType = fdp.ConsumeIntegral(), + .deviceIdHash = fdp.ConsumeRandomLengthString(), + .status = fdp.ConsumeIntegral(), + .validPeriod = fdp.ConsumeIntegral(), + .lastAuthTime = fdp.ConsumeIntegral(), + .bindLevel = fdp.ConsumeIntegral() }; + FromJson(jsonItemObject, control_table); +} +} // namespace DistributedHardware } /* Fuzzer entry point */ @@ -159,6 +238,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::AuthMessageProcessorFuzzTest(data, size); - + OHOS::DistributedHardware::AuthMessageProcessorFirstFuzzTest(data, size); + OHOS::DistributedHardware::AuthMessageProcessorSecondFuzzTest(data, size); return 0; } diff --git a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn index e769025ecf720aa789b5e680076772cf2d957812..a129f111d7fe9d2f2720506ed8ccd23dcbc79f88 100644 --- a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn @@ -63,7 +63,7 @@ ohos_fuzztest("DeviceNameManagerFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservice", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] defines = [ diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn b/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0b933d849dd8a22bf6cc9e8a3ba530768963403c --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2022-2025 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/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DmAuthAttestCommonFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/dmauthattestcommon_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/attest", + "${utils_path}/include/kvadapter", + "${json_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${servicesimpl_path}/src/adapter/standard/dm_adapter_manager.cpp", + "dm_auth_attest_common_fuzzer.cpp", + "${json_path}/src/json_object_cjson.cpp", + ] + + deps = [ + "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmAuthAttestCommonFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "safwk:system_ability_fwk", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmAuthAttestCommonFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init b/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..9c560fe896401f2d179c49f5946f5f1dc4a4b3ea --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2025 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 diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..799eed03bb5dc2c0aa7188559a4a56bcb09386c5 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 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 "dm_auth_attest_common_fuzzer.h" + +#include + +#include "dm_auth_attest_common.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmAuthAttestCommonFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + DmCertChain* chain = new DmCertChain; + chain->cert = new DmBlob[1]; + chain->certCount = 1; + int32_t maxLen = 65535; + chain->cert[0].size = size; + if (size > 0 && size <= maxLen) { + chain->cert[0].data = new uint8_t[size]; + *chain->cert[0].data = fdp.ConsumeIntegral(); + } + std::string str_value = fdp.ConsumeRandomLengthString(); + JsonItemObject jsonItem; + jsonItem.PushBack(str_value); + AuthAttestCommon::GetInstance().SerializeDmCertChain(nullptr); + AuthAttestCommon::GetInstance().SerializeDmCertChain(chain); + AuthAttestCommon::GetInstance().FreeDmCertChain(*chain); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmAuthAttestCommonFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e4e5a1fff7cec2c83d9086469918a326e23317dd --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H +#define DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H + +#define FUZZ_PROJECT_NAME "dmauthattestcommon_fuzzer" + +#endif // DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml b/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..500f6f414493290025d8dea9b066e5d5021a9377 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp index f8b0b9354412c9bd1ac7b07b3f0fae1872009f62..f8d04a6bd24777c55fb35bdd0d39b4ac1ab85418 100644 --- a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp +++ b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp @@ -62,6 +62,32 @@ void DmCommToolFuzzTest(const uint8_t* data, size_t size) dmCommToolPtr_->GetDMTransportPtr(); dmCommToolPtr_->GetEventHandler(); } + +void DmCommToolFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + DMCommTool::DMCommToolEventHandler dmCommToolEventHandler( + AppExecFwk::EventRunner::Create(FUZZ_PROJECT_NAME), dmCommToolPtr_); + + int32_t socketId = fdp.ConsumeIntegral(); + std::string rmtNetworkId = fdp.ConsumeRandomLengthString(); + int32_t code = fdp.ConsumeIntegral(); + std::string msg = fdp.ConsumeRandomLengthString(); + std::shared_ptr commMsg = std::make_shared(code, msg); + std::shared_ptr innrCommMsg = std::make_shared(rmtNetworkId, commMsg, socketId); + UserIdsMsg userIdsMsg; + userIdsMsg.foregroundUserIds.push_back(DATA_LEN); + dmCommToolEventHandler.ParseUserIdsMsg(innrCommMsg, userIdsMsg); + AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(commMsg->code, innrCommMsg); + dmCommToolEventHandler.ProcessEvent(event); + dmCommToolPtr_->ProcessResponseUserStopEvent(innrCommMsg); + std::string commonEventType; + EventCallback eventCallback; + dmCommToolPtr_->StartCommonEvent(commonEventType, eventCallback); +} } } @@ -70,5 +96,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmCommToolFuzzTest(data, size); + OHOS::DistributedHardware::DmCommToolFirstFuzzTest(data, size); return 0; } diff --git a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp index 663947393fd90036cde76c0d6d9d4efc114cb1e0..54d374cd781be2c91b577dfc234bf9e45d7350b6 100644 --- a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp +++ b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp @@ -86,6 +86,34 @@ void DmTransPortMsgFuzzTest(const uint8_t* data, size_t size) notifyUserIds.ToString(); cJSON_Delete(jsonObject); } +void DmTransPortMsgFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t code = fdp.ConsumeIntegral(); + std::string msg(reinterpret_cast(data), size); + std::string remoteUdid(reinterpret_cast(data), size); + const char* jsonString = R"({ + "MsgType": "0", + "userId": "12345", + "accountId": "a******3", + "peerUdids": ["u******1", "u******2"], + "peerUdid": "p******d", + "accountName": "t******t", + "syncUserIdFlag": 1, + "userIds": [ + {"type": 1, "userId": 111}, + {"type": 0, "userId": 222} + ] + })"; + cJSON* jsonObject = nullptr; + LogoutAccountMsg accountInfo; + ToJson(jsonObject, accountInfo); + FromJson(jsonObject, accountInfo); + cJSON_Delete(jsonObject); +} } } @@ -94,5 +122,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmTransPortMsgFuzzTest(data, size); + OHOS::DistributedHardware::DmTransPortMsgFirstFuzzTest(data, size); return 0; }