• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "devicestatussrvstub_fuzzer.h"
17 
18 #include "singleton.h"
19 
20 #define private public
21 #include "devicestatus_service.h"
22 #include "fi_log.h"
23 #include "message_parcel.h"
24 
25 #undef LOG_TAG
26 #define LOG_TAG "DeviceStatusStubFuzzTest"
27 
28 namespace OHOS {
29 namespace Msdp {
30 namespace DeviceStatus {
31 namespace OHOS {
32 const std::u16string FORMMGR_DEVICE_TOKEN { u"ohos.msdp.Idevicestatus" };
33 
StopDragStubFuzzTest(const uint8_t * data,size_t size)34 bool StopDragStubFuzzTest(const uint8_t* data, size_t size)
35 {
36     MessageParcel datas;
37     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
38         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
39         FI_HILOGE("Write failed");
40         return false;
41     }
42     MessageParcel reply;
43     MessageOption option;
44     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
45         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::STOP_DRAG), datas, reply, option);
46     return true;
47 }
48 
GetDragTargetPidFuzzTest(const uint8_t * data,size_t size)49 bool GetDragTargetPidFuzzTest(const uint8_t* data, size_t size)
50 {
51     MessageParcel datas;
52     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
53         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
54         FI_HILOGE("Write failed");
55         return false;
56     }
57     MessageParcel reply;
58     MessageOption option;
59     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
60         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::GET_DRAG_TARGET_PID), datas, reply, option);
61     return true;
62 }
63 
AddDraglistenerStubFuzzTest(const uint8_t * data,size_t size)64 bool AddDraglistenerStubFuzzTest(const uint8_t* data, size_t size)
65 {
66     MessageParcel datas;
67     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
68         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
69         FI_HILOGE("Write failed");
70         return false;
71     }
72     MessageParcel reply;
73     MessageOption option;
74     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
75         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::REGISTER_DRAG_MONITOR), datas, reply, option);
76     return true;
77 }
78 
RemoverDraglistenerStubFuzzTest(const uint8_t * data,size_t size)79 bool RemoverDraglistenerStubFuzzTest(const uint8_t* data, size_t size)
80 {
81     MessageParcel datas;
82     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
83         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
84         FI_HILOGE("Write failed");
85         return false;
86     }
87     MessageParcel reply;
88     MessageOption option;
89     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
90         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::UNREGISTER_DRAG_MONITOR), datas, reply, option);
91     return true;
92 }
93 
GethadowOffsetStubFuzzTest(const uint8_t * data,size_t size)94 bool GethadowOffsetStubFuzzTest(const uint8_t* data, size_t size)
95 {
96     MessageParcel datas;
97     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
98         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
99         FI_HILOGE("Write failed");
100         return false;
101     }
102     MessageParcel reply;
103     MessageOption option;
104     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
105         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::GET_SHADOW_OFFSET), datas, reply, option);
106     return true;
107 }
108 
GetDragStateStubFuzzTest(const uint8_t * data,size_t size)109 bool GetDragStateStubFuzzTest(const uint8_t* data, size_t size)
110 {
111     MessageParcel datas;
112     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
113         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
114         FI_HILOGE("Write failed");
115         return false;
116     }
117     MessageParcel reply;
118     MessageOption option;
119     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
120         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::GET_DRAG_STATE), datas, reply, option);
121     return true;
122 }
123 
GetDragSummaryStubFuzzTest(const uint8_t * data,size_t size)124 bool GetDragSummaryStubFuzzTest(const uint8_t* data, size_t size)
125 {
126     MessageParcel datas;
127     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
128         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
129         FI_HILOGE("Write failed");
130         return false;
131     }
132     MessageParcel reply;
133     MessageOption option;
134     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
135         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::GET_DRAG_SUMMARY), datas, reply, option);
136     return true;
137 }
138 
GetDragExtraInfoStubFuzzTest(const uint8_t * data,size_t size)139 bool GetDragExtraInfoStubFuzzTest(const uint8_t* data, size_t size)
140 {
141     MessageParcel datas;
142     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
143         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
144         FI_HILOGE("Write failed");
145         return false;
146     }
147     MessageParcel reply;
148     MessageOption option;
149     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
150         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::GET_DRAG_EXTRAINFO), datas, reply, option);
151     return true;
152 }
153 
GetDragActionStubFuzzTest(const uint8_t * data,size_t size)154 bool GetDragActionStubFuzzTest(const uint8_t* data, size_t size)
155 {
156     MessageParcel datas;
157     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
158         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
159         FI_HILOGE("Write failed");
160         return false;
161     }
162     MessageParcel reply;
163     MessageOption option;
164     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
165         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::GET_DRAG_ACTION), datas, reply, option);
166     return true;
167 }
168 
UpdatePreviewStyleStubFuzzTest(const uint8_t * data,size_t size)169 bool UpdatePreviewStyleStubFuzzTest(const uint8_t* data, size_t size)
170 {
171     MessageParcel datas;
172     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
173         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
174         FI_HILOGE("Write failed");
175         return false;
176     }
177     MessageParcel reply;
178     MessageOption option;
179     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
180         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::UPDATE_PREVIEW_STYLE), datas, reply, option);
181     return true;
182 }
183 
UpdatePreviewStyleWithAnimationStubFuzzTest(const uint8_t * data,size_t size)184 bool UpdatePreviewStyleWithAnimationStubFuzzTest(const uint8_t* data, size_t size)
185 {
186     MessageParcel datas;
187     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
188         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
189         FI_HILOGE("Write failed");
190         return false;
191     }
192     MessageParcel reply;
193     MessageOption option;
194     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
195         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::UPDATE_PREVIEW_STYLE_WITH_ANIMATION), datas, reply, option);
196     return true;
197 }
198 
AddPrivilegeStubFuzzTest(const uint8_t * data,size_t size)199 bool AddPrivilegeStubFuzzTest(const uint8_t* data, size_t size)
200 {
201     MessageParcel datas;
202     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
203         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
204         FI_HILOGE("Write failed");
205         return false;
206     }
207     MessageParcel reply;
208     MessageOption option;
209     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
210         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::ADD_PRIVILEGE), datas, reply, option);
211     return true;
212 }
213 
EraseMouseIconStubFuzzTest(const uint8_t * data,size_t size)214 bool EraseMouseIconStubFuzzTest(const uint8_t* data, size_t size)
215 {
216     MessageParcel datas;
217     if (!datas.WriteInterfaceToken(FORMMGR_DEVICE_TOKEN) ||
218         !datas.WriteBuffer(data, size) || !datas.RewindRead(0)) {
219         FI_HILOGE("Write failed");
220         return false;
221     }
222     MessageParcel reply;
223     MessageOption option;
224     DelayedSingleton<DeviceStatusService>::GetInstance()->OnRemoteRequest(
225         static_cast<uint32_t>(Msdp::DeviceInterfaceCode::ERASE_MOUSE_ICON), datas, reply, option);
226     return true;
227 }
228 } // namespace OHOS
229 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)230 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
231 {
232     /* Run your code on data */
233     if (data == nullptr) {
234         return 0;
235     }
236     OHOS::StopDragStubFuzzTest(data, size);
237     OHOS::GetDragTargetPidFuzzTest(data, size);
238     OHOS::AddDraglistenerStubFuzzTest(data, size);
239     OHOS::RemoverDraglistenerStubFuzzTest(data, size);
240     OHOS::GethadowOffsetStubFuzzTest(data, size);
241     OHOS::GetDragStateStubFuzzTest(data, size);
242     OHOS::GetDragSummaryStubFuzzTest(data, size);
243     OHOS::GetDragExtraInfoStubFuzzTest(data, size);
244     OHOS::GetDragActionStubFuzzTest(data, size);
245     OHOS::UpdatePreviewStyleStubFuzzTest(data, size);
246     OHOS::UpdatePreviewStyleWithAnimationStubFuzzTest(data, size);
247     OHOS::AddPrivilegeStubFuzzTest(data, size);
248     OHOS::EraseMouseIconStubFuzzTest(data, size);
249     return 0;
250 }
251 } // namespace DeviceStatus
252 } // namespace Msdp
253 } // namespace OHOS