1 /*
2 * Copyright (c) 2022 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
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
35 namespace OHOS {
36 namespace DistributedHardware {
IpcServerStubFuzzTest(const uint8_t * data,size_t size)37 void IpcServerStubFuzzTest(const uint8_t* data, size_t size)
38 {
39 if ((data == nullptr) || (size < sizeof(uint32_t))) {
40 return;
41 }
42 uint32_t code = *(reinterpret_cast<const uint32_t*>(data));
43 MessageParcel data1;
44 MessageParcel reply;
45 MessageOption option;
46 std::string pkgName(reinterpret_cast<const char*>(data), size);
47 sptr<IpcRemoteBroker> listener = nullptr;
48 std::shared_ptr<IpcReq> req = nullptr;
49 std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
50
51 IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option);
52 IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
53 IpcServerStub::GetInstance().GetDmListener(pkgName);
54 IpcServerStub::GetInstance().SendCmd(code, req, rsp);
55 IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
56 }
57 }
58 }
59
60 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63 /* Run your code on data */
64 OHOS::DistributedHardware::IpcServerStubFuzzTest(data, size);
65 return 0;
66 }