• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_get_dmfaparam_rsp.h"
36 #include "ipc_register_dev_state_callback_req.h"
37 #include "ipc_set_useroperation_req.h"
38 #include "ipc_verify_authenticate_req.h"
39 #include "ipc_unauthenticate_device_req.h"
40 #include "ipc_rsp.h"
41 
42 namespace OHOS {
43 namespace DistributedHardware {
IpcCmdRegisterFuzzTest(const uint8_t * data,size_t size)44 void IpcCmdRegisterFuzzTest(const uint8_t* data, size_t size)
45 {
46     if ((data == nullptr) || (size == 0)) {
47         return;
48     }
49     int32_t cmdCode = UNREGISTER_DEVICE_MANAGER_LISTENER;
50     std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
51     std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
52     MessageParcel data1;
53     MessageParcel reply1;
54 
55     IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data1);
56     IpcCmdRegister::GetInstance().ReadResponse(cmdCode, data1, rsp);
57     IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data1, reply1);
58 }
59 }
60 }
61 
62 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)63 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
64 {
65     /* Run your code on data */
66     OHOS::DistributedHardware::IpcCmdRegisterFuzzTest(data, size);
67     return 0;
68 }
69