1 /*
2 * Copyright (c) 2022-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 <algorithm>
17 #include <thread>
18 #include <unistd.h>
19 #include <fuzzer/FuzzedDataProvider.h>
20 #include "ipc_client_stub.h"
21 #include "dm_device_info.h"
22 #include "ipc_server_stub.h"
23 #include "device_manager_impl.h"
24 #include "dm_constants.h"
25 #include "if_system_ability_manager.h"
26 #include "ipc_cmd_register.h"
27 #include "ipc_remote_broker.h"
28 #include "ipc_skeleton.h"
29 #include "ipc_types.h"
30 #include "iservice_registry.h"
31 #include "string_ex.h"
32 #include "system_ability_definition.h"
33 #include "ipc_server_stub_fuzzer.h"
34 #include "iremote_object.h"
35
36 namespace OHOS {
37 namespace DistributedHardware {
IpcServerStubFuzzTest(const uint8_t * data,size_t size)38 void IpcServerStubFuzzTest(const uint8_t* data, size_t size)
39 {
40 if ((data == nullptr) || (size < sizeof(uint32_t))) {
41 return;
42 }
43 FuzzedDataProvider fdp(data, size);
44 uint32_t code = fdp.ConsumeIntegral<uint32_t>();
45 MessageParcel data1;
46 MessageParcel reply;
47 MessageOption option;
48 ProcessInfo processInfo;
49 std::string pkgName(reinterpret_cast<const char*>(data), size);
50 processInfo.pkgName = pkgName;
51 sptr<IpcRemoteBroker> listener = sptr<IpcServerStub>(new IpcServerStub());
52 std::shared_ptr<IpcReq> req = nullptr;
53 std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
54
55 IpcServerStub::GetInstance().Init();
56 IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option);
57 IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener);
58 IpcServerStub::GetInstance().GetDmListener(processInfo);
59 IpcServerStub::GetInstance().SendCmd(code, req, rsp);
60 IpcServerStub::GetInstance().GetAllProcessInfo();
61 IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo);
62 }
63 }
64 }
65
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69 /* Run your code on data */
70 OHOS::DistributedHardware::IpcServerStubFuzzTest(data, size);
71 return 0;
72 }