• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "softbus_connector.h"
17 #include "softbus_bus_center.h"
18 #include "dm_device_info.h"
19 #include "dm_publish_info.h"
20 #include "dm_publish_manager.h"
21 #include "dm_subscribe_info.h"
22 #include "softbus_discovery_callback.h"
23 #include "softbus_publish_callback.h"
24 #include "softbus_session.h"
25 #include "softbus_connector_register_fuzzer.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 class SoftbusDiscoveryCallbackFuzzTest : public ISoftbusDiscoveryCallback {
30 public:
~SoftbusDiscoveryCallbackFuzzTest()31     virtual ~SoftbusDiscoveryCallbackFuzzTest() {}
32 
OnDeviceFound(const std::string & pkgName,DmDeviceInfo & info,bool isOnline)33     void OnDeviceFound(const std::string &pkgName, DmDeviceInfo &info, bool isOnline) override {}
OnDiscoverySuccess(const std::string & pkgName,int32_t subscribeId)34     void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) override {}
OnDiscoveryFailed(const std::string & pkgName,int32_t subscribeId,int32_t failedReason)35     void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason) override {}
36 };
37 
38 class SoftbusPublishCallbackFuzzTest : public ISoftbusPublishCallback {
39 public:
~SoftbusPublishCallbackFuzzTest()40     virtual ~SoftbusPublishCallbackFuzzTest() {}
41 
OnPublishResult(const std::string & pkgName,int32_t publishId,int32_t publishResult)42     void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) override {}
43 };
44 
SoftBusConnectorRegisterFuzzTest(const uint8_t * data,size_t size)45 void SoftBusConnectorRegisterFuzzTest(const uint8_t* data, size_t size)
46 {
47     if ((data == nullptr) || (size == 0)) {
48         return;
49     }
50 
51     std::string pkgName(reinterpret_cast<const char*>(data), size);
52     std::shared_ptr<ISoftbusPublishCallback> pubishCallback = std::make_shared<SoftbusPublishCallbackFuzzTest>();
53     std::shared_ptr<ISoftbusDiscoveryCallback> discoveryCallback = std::make_shared<SoftbusDiscoveryCallbackFuzzTest>();
54     std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
55 
56     softbusConnector->RegisterSoftbusDiscoveryCallback(pkgName, discoveryCallback);
57     softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
58     softbusConnector->RegisterSoftbusPublishCallback(pkgName, pubishCallback);
59     softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
60 }
61 }
62 }
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67     /* Run your code on data */
68     OHOS::DistributedHardware::SoftBusConnectorRegisterFuzzTest(data, size);
69 
70     return 0;
71 }
72