1 /*
2 * Copyright (c) 2023-2024 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 "capabilityinfomanager_fuzzer.h"
17
18 #include "capability_info_manager.h"
19 #include "distributed_hardware_log.h"
20
21 namespace OHOS {
22 namespace DistributedHardware {
23
CapabilityInfoManagerFuzzTest(const uint8_t * data,size_t size)24 void CapabilityInfoManagerFuzzTest(const uint8_t* data, size_t size)
25 {
26 if ((data == nullptr) || (size <= sizeof(DistributedKv::ChangeNotification))) {
27 return;
28 }
29
30 DistributedKv::Entry insert;
31 DistributedKv::Entry update;
32 DistributedKv::Entry del;
33 insert.key = std::string(reinterpret_cast<const char*>(data), size);
34 update.key = std::string(reinterpret_cast<const char*>(data), size);
35 del.key = std::string(reinterpret_cast<const char*>(data), size);
36 insert.value = std::string(reinterpret_cast<const char*>(data), size);
37 update.value = std::string(reinterpret_cast<const char*>(data), size);
38 del.value = std::string(reinterpret_cast<const char*>(data), size);
39 std::vector<DistributedKv::Entry> inserts;
40 std::vector<DistributedKv::Entry> updates;
41 std::vector<DistributedKv::Entry> deleteds;
42 inserts.push_back(insert);
43 updates.push_back(update);
44 deleteds.push_back(del);
45 std::string deviceId(reinterpret_cast<const char*>(data), size);
46
47 DistributedKv::ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds),
48 deviceId, true);
49 CapabilityInfoManager::GetInstance()->OnChange(changeIn);
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::CapabilityInfoManagerFuzzTest(data, size);
59 return 0;
60 }
61
62