• 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 <cstddef>
17 #include <cstdint>
18 #include <string>
19 #include <unistd.h>
20 
21 #include "device_manager_impl.h"
22 #include "device_manager.h"
23 #include "device_manager_callback.h"
24 #include "register_device_manager_fa_callback_fuzzer.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 namespace {
29     constexpr uint32_t SLEEP_TIME_US = 10 * 1000;
30 }
31 
32 class DeviceManagerFaCallbackTest : public DeviceManagerUiCallback {
33 public:
DeviceManagerFaCallbackTest()34     DeviceManagerFaCallbackTest() : DeviceManagerUiCallback() {}
~DeviceManagerFaCallbackTest()35     ~DeviceManagerFaCallbackTest() override {}
OnCall(const std::string & paramJson)36     void OnCall(const std::string &paramJson) override {}
37 };
38 
RegisterDeviceManagerFaCallbackFuzzTest(const uint8_t * data,size_t size)39 void RegisterDeviceManagerFaCallbackFuzzTest(const uint8_t* data, size_t size)
40 {
41     if ((data == nullptr) || (size == 0)) {
42         return;
43     }
44 
45     std::string packageName(reinterpret_cast<const char*>(data), size);
46     std::shared_ptr<DeviceManagerFaCallbackTest> callback = std::make_shared<DeviceManagerFaCallbackTest>();
47 
48     DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback);
49     usleep(SLEEP_TIME_US);
50 }
51 }
52 }
53 
54 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)55 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
56 {
57     /* Run your code on data */
58     OHOS::DistributedHardware::RegisterDeviceManagerFaCallbackFuzzTest(data, size);
59     return 0;
60 }
61