1 /*
2 * Copyright (c) 2021-2023 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 #include "ipc_cmd_register_fuzzer.h"
16
17 #include <chrono>
18 #include <cstddef>
19 #include <cstdint>
20 #include <string>
21 #include <unistd.h>
22
23 #include "device_manager_ipc_interface_code.h"
24 #include "ipc_cmd_register.h"
25 #include "ipc_client_manager.h"
26 #include "ipc_register_listener_req.h"
27 #include "ipc_get_trustdevice_rsp.h"
28 #include "ipc_get_info_by_network_rsp.h"
29 #include "ipc_get_info_by_network_req.h"
30 #include "ipc_get_trustdevice_req.h"
31 #include "ipc_start_discovery_req.h"
32 #include "ipc_stop_discovery_req.h"
33 #include "ipc_publish_req.h"
34 #include "ipc_unpublish_req.h"
35 #include "ipc_set_useroperation_req.h"
36 #include "ipc_unauthenticate_device_req.h"
37 #include "ipc_rsp.h"
38
39 namespace OHOS {
40 namespace DistributedHardware {
IpcCmdRegisterFuzzTest(const uint8_t* data, size_t size)41 void IpcCmdRegisterFuzzTest(const uint8_t* data, size_t size)
42 {
43 if ((data == nullptr) || (size == 0)) {
44 return;
45 }
46 int32_t cmdCode = UNREGISTER_DEVICE_MANAGER_LISTENER;
47 std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
48 std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
49 MessageParcel data1;
50 MessageParcel reply1;
51
52 IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data1);
53 IpcCmdRegister::GetInstance().ReadResponse(cmdCode, data1, rsp);
54 IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data1, reply1);
55 }
56 }
57 }
58
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
61 {
62 /* Run your code on data */
63 OHOS::DistributedHardware::IpcCmdRegisterFuzzTest(data, size);
64 return 0;
65 }
66