• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_skeleton.h"
28 #include "ipc_types.h"
29 #include "iservice_registry.h"
30 #include "string_ex.h"
31 #include "system_ability_definition.h"
32 #include "ipc_server_stub_fuzzer.h"
33 
34 namespace OHOS {
35 namespace DistributedHardware {
IpcServerStubFuzzTest(const uint8_t * data,size_t size)36 void IpcServerStubFuzzTest(const uint8_t* data, size_t size)
37 {
38     if ((data == nullptr) || (size < sizeof(uint32_t))) {
39         return;
40     }
41     uint32_t code = *(reinterpret_cast<const uint32_t*>(data));
42     MessageParcel data1;
43     MessageParcel reply;
44     MessageOption option;
45     std::string pkgName(reinterpret_cast<const char*>(data), size);
46     sptr<IRemoteObject> listener = nullptr;
47     std::shared_ptr<IpcReq> req = nullptr;
48     std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
49 
50     IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option);
51     IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
52     IpcServerStub::GetInstance().GetDmListener(pkgName);
53     IpcServerStub::GetInstance().SendCmd(code, req, rsp);
54     IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
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::IpcServerStubFuzzTest(data, size);
64     return 0;
65 }