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 "enabledcompsdump_fuzzer.h"
17
18 #include <algorithm>
19 #include <chrono>
20 #include <cstddef>
21 #include <cstdint>
22 #include <string>
23 #include <unistd.h>
24
25 #include "distributed_hardware_errno.h"
26 #include "enabled_comps_dump.h"
27
28 namespace OHOS {
29 namespace DistributedHardware {
30 namespace {
31 const uint32_t DH_TYPE_SIZE = 10;
32 const DHType dhTypeFuzz[DH_TYPE_SIZE] = {
33 DHType::CAMERA, DHType::AUDIO, DHType::SCREEN, DHType::VIRMODEM_AUDIO,
34 DHType::INPUT, DHType::A2D, DHType::GPS, DHType::HFP
35 };
36 }
37
EnableedCompsDumpFuzzTest(const uint8_t * data,size_t size)38 void EnableedCompsDumpFuzzTest(const uint8_t* data, size_t size)
39 {
40 if ((data == nullptr) || (size == 0)) {
41 return;
42 }
43
44 std::string networkId(reinterpret_cast<const char*>(data), size);
45 std::string dhId(reinterpret_cast<const char*>(data), size);
46 DHType dhType = dhTypeFuzz[data[0] % DH_TYPE_SIZE];
47
48 std::set<HidumpCompInfo> compInfoSet {};
49 EnabledCompsDump::GetInstance().DumpEnabledComp(networkId, dhType, dhId);
50 EnabledCompsDump::GetInstance().Dump(compInfoSet);
51 EnabledCompsDump::GetInstance().DumpDisabledComp(networkId, dhType, dhId);
52 }
53 }
54 }
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 OHOS::DistributedHardware::EnableedCompsDumpFuzzTest(data, size);
61 return 0;
62 }
63
64