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