1 /*
2 * Copyright (c) 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 <cstddef>
17 #include <cstdint>
18 #include <parcel.h>
19 #include <securec.h>
20
21 #include <iremote_stub.h>
22 #include "message_option.h"
23 #include "message_parcel.h"
24 #include "marshalling_helper.h"
25 #include "screen_session_manager_client_interface.h"
26 #include "screen_session_manager_client_stub.h"
27 #include "screensessionmanagerclientstub_fuzzer.h"
28 #include "screen_session_manager_client.h"
29
30 using namespace OHOS::Rosen;
31
32 namespace OHOS {
33 namespace {
34 constexpr size_t DATA_MIN_SIZE = 2;
35 }
36 template<class T>
GetObject(T & object,const uint8_t * data,size_t size)37 size_t GetObject(T &object, const uint8_t *data, size_t size)
38 {
39 size_t objectSize = sizeof(object);
40 if (objectSize > size) {
41 return 0;
42 }
43 return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0;
44 }
ScreenSessionMgrClientStubTest1(MessageParcel & parcel,MessageParcel & reply,MessageOption & option)45 void ScreenSessionMgrClientStubTest1(MessageParcel &parcel, MessageParcel &reply, MessageOption &option)
46 {
47 parcel.RewindRead(0);
48 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
49 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
50 ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_CONNECTION_CHANGED), parcel, reply, option);
51 parcel.RewindRead(0);
52 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
53 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
54 ScreenSessionManagerClientMessage::TRANS_ID_ON_PROPERTY_CHANGED), parcel, reply, option);
55 parcel.RewindRead(0);
56 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
57 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
58 ScreenSessionManagerClientMessage::TRANS_ID_ON_POWER_STATUS_CHANGED), parcel, reply, option);
59 parcel.RewindRead(0);
60 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
61 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
62 ScreenSessionManagerClientMessage::TRANS_ID_ON_SENSOR_ROTATION_CHANGED), parcel, reply, option);
63 parcel.RewindRead(0);
64 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
65 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
66 ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_ORIENTATION_CHANGED), parcel, reply, option);
67 parcel.RewindRead(0);
68 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
69 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
70 ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_ROTATION_LOCKED_CHANGED), parcel, reply, option);
71 parcel.RewindRead(0);
72 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
73 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
74 ScreenSessionManagerClientMessage::TRANS_ID_ON_DISPLAY_STATE_CHANGED), parcel, reply, option);
75 return;
76 }
ScreenSessionMgrClientStubTest2(MessageParcel & parcel,MessageParcel & reply,MessageOption & option)77 void ScreenSessionMgrClientStubTest2(MessageParcel &parcel, MessageParcel &reply, MessageOption &option)
78 {
79 parcel.RewindRead(0);
80 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
81 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
82 ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_SHOT), parcel, reply, option);
83 parcel.RewindRead(0);
84 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
85 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
86 ScreenSessionManagerClientMessage::TRANS_ID_ON_IMMERSIVE_STATE_CHANGED), parcel, reply, option);
87 parcel.RewindRead(0);
88 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
89 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
90 ScreenSessionManagerClientMessage::TRANS_ID_SET_DISPLAY_NODE_SCREEN_ID), parcel, reply, option);
91 parcel.RewindRead(0);
92 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
93 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
94 ScreenSessionManagerClientMessage::TRANS_ID_GET_SURFACENODEID_FROM_MISSIONID), parcel, reply, option);
95 parcel.RewindRead(0);
96 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
97 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
98 ScreenSessionManagerClientMessage::TRANS_ID_SET_FOLD_DISPLAY_MODE), parcel, reply, option);
99 parcel.RewindRead(0);
100 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
101 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
102 ScreenSessionManagerClientMessage::TRANS_ID_ON_SWITCH_USER_CMD), parcel, reply, option);
103 parcel.RewindRead(0);
104 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
105 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
106 ScreenSessionManagerClientMessage::TRANS_ID_SET_VIRTUAL_PIXEL_RATIO_SYSTEM), parcel, reply, option);
107 return;
108 }
ScreenSessionMgrClientStubTest3(MessageParcel & parcel,MessageParcel & reply,MessageOption & option)109 void ScreenSessionMgrClientStubTest3(MessageParcel &parcel, MessageParcel &reply, MessageOption &option)
110 {
111 parcel.RewindRead(0);
112 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
113 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
114 ScreenSessionManagerClientMessage::TRANS_ID_ON_FOLDSTATUS_CHANGED_REPORT_UE), parcel, reply, option);
115 parcel.RewindRead(0);
116 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
117 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
118 ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_CAPTURE_NOTIFY), parcel, reply, option);
119 parcel.RewindRead(0);
120 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
121 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
122 ScreenSessionManagerClientMessage::TRANS_ID_ON_SUPER_FOLD_STATUS_CHANGED), parcel, reply, option);
123 parcel.RewindRead(0);
124 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
125 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
126 ScreenSessionManagerClientMessage::TRANS_ID_ON_HOVER_STATUS_CHANGED), parcel, reply, option);
127 parcel.RewindRead(0);
128 ScreenSessionManagerClient::GetInstance().OnRemoteRequest(
129 static_cast<uint32_t>(Rosen::IScreenSessionManagerClient::
130 ScreenSessionManagerClientMessage::TRANS_ID_ON_SCREEN_EXTEND_CHANGED), parcel, reply, option);
131 return;
132 }
133
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)134 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
135 {
136 if (data == nullptr || size < DATA_MIN_SIZE) {
137 return false;
138 }
139
140 MessageParcel parcel;
141 MessageParcel reply;
142 MessageOption option;
143
144 parcel.WriteInterfaceToken(ScreenSessionManagerClientStub::GetDescriptor());
145 parcel.WriteBuffer(data, size);
146
147 ScreenSessionMgrClientStubTest1(parcel, reply, option);
148 ScreenSessionMgrClientStubTest2(parcel, reply, option);
149 ScreenSessionMgrClientStubTest3(parcel, reply, option);
150 return true;
151 }
152 } // namespace.OHOS
153
154 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)155 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
156 {
157 /* Run your code on data */
158 OHOS::DoSomethingInterestingWithMyAPI(data, size);
159 return 0;
160 }