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 "locatorabilitystub_fuzzer.h"
17 
18 #include "accesstoken_kit.h"
19 #include "if_system_ability_manager.h"
20 #include "iservice_registry.h"
21 #include "message_option.h"
22 #include "message_parcel.h"
23 #include "nativetoken_kit.h"
24 #include "system_ability_definition.h"
25 #include "token_setproc.h"
26 #include "locator_ability.h"
27 #include "locationhub_ipc_interface_code.h"
28 #include "permission_manager.h"
29 
30 namespace OHOS {
31 using namespace OHOS::Location;
32 const int32_t MAX_MEM_SIZE = 4 * 1024 * 1024;
33 const int32_t LOCATION_PERM_NUM = 4;
34 const int32_t WAIT_EVENT_TIME = 3;
MockNativePermission()35 void MockNativePermission()
36 {
37     const char *perms[] = {
38         ACCESS_LOCATION.c_str(), ACCESS_APPROXIMATELY_LOCATION.c_str(),
39         ACCESS_BACKGROUND_LOCATION.c_str(), MANAGE_SECURE_SETTINGS.c_str(),
40     };
41     NativeTokenInfoParams infoInstance = {
42         .dcapsNum = 0,
43         .permsNum = LOCATION_PERM_NUM,
44         .aclsNum = 0,
45         .dcaps = nullptr,
46         .perms = perms,
47         .acls = nullptr,
48         .processName = "LocatorAbility_FuzzTest",
49         .aplStr = "system_basic",
50     };
51     auto tokenId = GetAccessTokenId(&infoInstance);
52     SetSelfTokenID(tokenId);
53     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
54     LocatorAbility::GetInstance()->EnableAbility(true);
55 }
56 
ParseData(const uint8_t* data, size_t size)57 char* ParseData(const uint8_t* data, size_t size)
58 {
59     if (data == nullptr) {
60         return nullptr;
61     }
62 
63     if (size > MAX_MEM_SIZE) {
64         return nullptr;
65     }
66 
67     char* ch = (char *)malloc(size + 1);
68     if (ch == nullptr) {
69         return nullptr;
70     }
71 
72     (void)memset_s(ch, size + 1, 0x00, size + 1);
73     if (memcpy_s(ch, size, data, size) != EOK) {
74         free(ch);
75         ch = nullptr;
76         return nullptr;
77     }
78     return ch;
79 }
80 
LocatorAbilityStub001FuzzTest(const char* data, size_t size)81 bool LocatorAbilityStub001FuzzTest(const char* data, size_t size)
82 {
83     MessageParcel requestParcel;
84     requestParcel.WriteInterfaceToken(u"location.ILocator");
85     requestParcel.WriteBuffer(data, size);
86     requestParcel.RewindRead(0);
87 
88     MessageParcel reply;
89     MessageOption option;
90 
91     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
92     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::DISABLE_LOCATION_MOCK),
93         requestParcel, reply, option);
94 
95     return true;
96 }
97 
LocatorAbilityStub002FuzzTest(const char* data, size_t size)98 bool LocatorAbilityStub002FuzzTest(const char* data, size_t size)
99 {
100     MessageParcel requestParcel;
101     requestParcel.WriteInterfaceToken(u"location.ILocator");
102     requestParcel.WriteBuffer(data, size);
103     requestParcel.RewindRead(0);
104 
105     MessageParcel reply;
106     MessageOption option;
107 
108     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
109     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::ENABLE_ABILITY),
110         requestParcel, reply, option);
111 
112     return true;
113 }
114 
LocatorAbilityStub003FuzzTest(const char* data, size_t size)115 bool LocatorAbilityStub003FuzzTest(const char* data, size_t size)
116 {
117     MessageParcel requestParcel;
118     requestParcel.WriteInterfaceToken(u"location.ILocator");
119     requestParcel.WriteBuffer(data, size);
120     requestParcel.RewindRead(0);
121 
122     MessageParcel reply;
123     MessageOption option;
124 
125     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
126     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::ENABLE_LOCATION_MOCK),
127         requestParcel, reply, option);
128 
129     return true;
130 }
131 
LocatorAbilityStub004FuzzTest(const char* data, size_t size)132 bool LocatorAbilityStub004FuzzTest(const char* data, size_t size)
133 {
134     MessageParcel requestParcel;
135     requestParcel.WriteInterfaceToken(u"location.ILocator");
136     requestParcel.WriteBuffer(data, size);
137     requestParcel.RewindRead(0);
138 
139     MessageParcel reply;
140     MessageOption option;
141 
142     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
143     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_CACHE_LOCATION),
144         requestParcel, reply, option);
145 
146     return true;
147 }
148 
LocatorAbilityStub005FuzzTest(const char* data, size_t size)149 bool LocatorAbilityStub005FuzzTest(const char* data, size_t size)
150 {
151     MessageParcel requestParcel;
152     requestParcel.WriteInterfaceToken(u"location.ILocator");
153     requestParcel.WriteBuffer(data, size);
154     requestParcel.RewindRead(0);
155 
156     MessageParcel reply;
157     MessageOption option;
158 
159     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
160     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_ISO_COUNTRY_CODE),
161         requestParcel, reply, option);
162 
163     return true;
164 }
165 
LocatorAbilityStub006FuzzTest(const char* data, size_t size)166 bool LocatorAbilityStub006FuzzTest(const char* data, size_t size)
167 {
168     MessageParcel requestParcel;
169     requestParcel.WriteInterfaceToken(u"location.ILocator");
170     requestParcel.WriteBuffer(data, size);
171     requestParcel.RewindRead(0);
172 
173     MessageParcel reply;
174     MessageOption option;
175 
176     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
177     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_SWITCH_STATE),
178         requestParcel, reply, option);
179 
180     return true;
181 }
182 
LocatorAbilityStub007FuzzTest(const char* data, size_t size)183 bool LocatorAbilityStub007FuzzTest(const char* data, size_t size)
184 {
185     MessageParcel requestParcel;
186     requestParcel.WriteInterfaceToken(u"location.ILocator");
187     requestParcel.WriteBuffer(data, size);
188     requestParcel.RewindRead(0);
189 
190     MessageParcel reply;
191     MessageOption option;
192 
193     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
194     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::IS_PRIVACY_COMFIRMED),
195         requestParcel, reply, option);
196 
197     return true;
198 }
199 
LocatorAbilityStub008FuzzTest(const char* data, size_t size)200 bool LocatorAbilityStub008FuzzTest(const char* data, size_t size)
201 {
202     MessageParcel requestParcel;
203     requestParcel.WriteInterfaceToken(u"location.ILocator");
204     requestParcel.WriteBuffer(data, size);
205     requestParcel.RewindRead(0);
206 
207     MessageParcel reply;
208     MessageOption option;
209 
210     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
211     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::PROXY_PID_FOR_FREEZE),
212         requestParcel, reply, option);
213 
214     return true;
215 }
216 
LocatorAbilityStub009FuzzTest(const char* data, size_t size)217 bool LocatorAbilityStub009FuzzTest(const char* data, size_t size)
218 {
219     MessageParcel requestParcel;
220     requestParcel.WriteInterfaceToken(u"location.ILocator");
221     requestParcel.WriteBuffer(data, size);
222     requestParcel.RewindRead(0);
223 
224     MessageParcel reply;
225     MessageOption option;
226 
227     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
228     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_COUNTRY_CODE_CALLBACK),
229         requestParcel, reply, option);
230 
231     return true;
232 }
233 
LocatorAbilityStub010FuzzTest(const char* data, size_t size)234 bool LocatorAbilityStub010FuzzTest(const char* data, size_t size)
235 {
236     MessageParcel requestParcel;
237     requestParcel.WriteInterfaceToken(u"location.ILocator");
238     requestParcel.WriteBuffer(data, size);
239     requestParcel.RewindRead(0);
240 
241     MessageParcel reply;
242     MessageOption option;
243 
244     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
245     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_SWITCH_CALLBACK),
246         requestParcel, reply, option);
247 
248     return true;
249 }
250 
LocatorAbilityStub011FuzzTest(const char* data, size_t size)251 bool LocatorAbilityStub011FuzzTest(const char* data, size_t size)
252 {
253     MessageParcel requestParcel;
254     requestParcel.WriteInterfaceToken(u"location.ILocator");
255     requestParcel.WriteBuffer(data, size);
256     requestParcel.RewindRead(0);
257 
258     MessageParcel reply;
259     MessageOption option;
260 
261     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
262     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REPORT_LOCATION),
263         requestParcel, reply, option);
264 
265     return true;
266 }
267 
LocatorAbilityStub012FuzzTest(const char* data, size_t size)268 bool LocatorAbilityStub012FuzzTest(const char* data, size_t size)
269 {
270     MessageParcel requestParcel;
271     requestParcel.WriteInterfaceToken(u"location.ILocator");
272     requestParcel.WriteBuffer(data, size);
273     requestParcel.RewindRead(0);
274 
275     MessageParcel reply;
276     MessageOption option;
277 
278     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
279     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::RESET_ALL_PROXY),
280         requestParcel, reply, option);
281 
282     return true;
283 }
284 
LocatorAbilityStub013FuzzTest(const char* data, size_t size)285 bool LocatorAbilityStub013FuzzTest(const char* data, size_t size)
286 {
287     MessageParcel requestParcel;
288     requestParcel.WriteInterfaceToken(u"location.ILocator");
289     requestParcel.WriteBuffer(data, size);
290     requestParcel.RewindRead(0);
291 
292     MessageParcel reply;
293     MessageOption option;
294 
295     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
296     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::SET_MOCKED_LOCATIONS),
297         requestParcel, reply, option);
298 
299     return true;
300 }
301 
LocatorAbilityStub014FuzzTest(const char* data, size_t size)302 bool LocatorAbilityStub014FuzzTest(const char* data, size_t size)
303 {
304     MessageParcel requestParcel;
305     requestParcel.WriteInterfaceToken(u"location.ILocator");
306     requestParcel.WriteBuffer(data, size);
307     requestParcel.RewindRead(0);
308 
309     MessageParcel reply;
310     MessageOption option;
311 
312     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
313     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::SET_PRIVACY_COMFIRM_STATUS),
314         requestParcel, reply, option);
315     return true;
316 }
317 
LocatorAbilityStub015FuzzTest(const char* data, size_t size)318 bool LocatorAbilityStub015FuzzTest(const char* data, size_t size)
319 {
320     MessageParcel requestParcel;
321     requestParcel.WriteInterfaceToken(u"location.ILocator");
322     requestParcel.WriteBuffer(data, size);
323     requestParcel.RewindRead(0);
324 
325     MessageParcel reply;
326     MessageOption option;
327 
328     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
329     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::START_LOCATING),
330         requestParcel, reply, option);
331 
332     return true;
333 }
334 
LocatorAbilityStub016FuzzTest(const char* data, size_t size)335 bool LocatorAbilityStub016FuzzTest(const char* data, size_t size)
336 {
337     MessageParcel requestParcel;
338     requestParcel.WriteInterfaceToken(u"location.ILocator");
339     requestParcel.WriteBuffer(data, size);
340     requestParcel.RewindRead(0);
341 
342     MessageParcel reply;
343     MessageOption option;
344 
345     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
346     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::STOP_LOCATING),
347         requestParcel, reply, option);
348 
349     return true;
350 }
351 
LocatorAbilityStub017FuzzTest(const char* data, size_t size)352 bool LocatorAbilityStub017FuzzTest(const char* data, size_t size)
353 {
354     MessageParcel requestParcel;
355     requestParcel.WriteInterfaceToken(u"location.ILocator");
356     requestParcel.WriteBuffer(data, size);
357     requestParcel.RewindRead(0);
358 
359     MessageParcel reply;
360     MessageOption option;
361 
362     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
363     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UPDATE_SA_ABILITY),
364         requestParcel, reply, option);
365     return true;
366 }
367 
LocatorAbilityStub018FuzzTest(const char* data, size_t size)368 bool LocatorAbilityStub018FuzzTest(const char* data, size_t size)
369 {
370     MessageParcel requestParcel;
371     requestParcel.WriteInterfaceToken(u"location.ILocator");
372     requestParcel.WriteBuffer(data, size);
373     requestParcel.RewindRead(0);
374 
375     MessageParcel reply;
376     MessageOption option;
377 
378     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
379     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::DISABLE_REVERSE_GEOCODE_MOCK),
380         requestParcel, reply, option);
381 
382     return true;
383 }
384 
LocatorAbilityStub019FuzzTest(const char* data, size_t size)385 bool LocatorAbilityStub019FuzzTest(const char* data, size_t size)
386 {
387     MessageParcel requestParcel;
388     requestParcel.WriteInterfaceToken(u"location.ILocator");
389     requestParcel.WriteBuffer(data, size);
390     requestParcel.RewindRead(0);
391 
392     MessageParcel reply;
393     MessageOption option;
394 
395     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
396     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::ENABLE_REVERSE_GEOCODE_MOCK),
397         requestParcel, reply, option);
398 
399     return true;
400 }
401 
LocatorAbilityStub020FuzzTest(const char* data, size_t size)402 bool LocatorAbilityStub020FuzzTest(const char* data, size_t size)
403 {
404     MessageParcel requestParcel;
405     requestParcel.WriteInterfaceToken(u"location.ILocator");
406     requestParcel.WriteBuffer(data, size);
407     requestParcel.RewindRead(0);
408 
409     MessageParcel reply;
410     MessageOption option;
411 
412     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
413     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GEO_IS_AVAILABLE),
414         requestParcel, reply, option);
415 
416     return true;
417 }
418 
LocatorAbilityStub021FuzzTest(const char* data, size_t size)419 bool LocatorAbilityStub021FuzzTest(const char* data, size_t size)
420 {
421     MessageParcel requestParcel;
422     requestParcel.WriteInterfaceToken(u"location.ILocator");
423     requestParcel.WriteBuffer(data, size);
424     requestParcel.RewindRead(0);
425 
426     MessageParcel reply;
427     MessageOption option;
428 
429     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
430     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_FROM_COORDINATE),
431         requestParcel, reply, option);
432 
433     return true;
434 }
435 
LocatorAbilityStub022FuzzTest(const char* data, size_t size)436 bool LocatorAbilityStub022FuzzTest(const char* data, size_t size)
437 {
438     MessageParcel requestParcel;
439     requestParcel.WriteInterfaceToken(u"location.ILocator");
440     requestParcel.WriteBuffer(data, size);
441     requestParcel.RewindRead(0);
442 
443     MessageParcel reply;
444     MessageOption option;
445 
446     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
447     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_FROM_LOCATION_NAME),
448         requestParcel, reply, option);
449 
450     return true;
451 }
452 
LocatorAbilityStub023FuzzTest(const char* data, size_t size)453 bool LocatorAbilityStub023FuzzTest(const char* data, size_t size)
454 {
455     MessageParcel requestParcel;
456     requestParcel.WriteInterfaceToken(u"location.ILocator");
457     requestParcel.WriteBuffer(data, size);
458     requestParcel.RewindRead(0);
459 
460     MessageParcel reply;
461     MessageOption option;
462 
463     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
464     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::SET_REVERSE_GEOCODE_MOCKINFO),
465         requestParcel, reply, option);
466 
467     return true;
468 }
469 
LocatorAbilityStub024FuzzTest(const char* data, size_t size)470 bool LocatorAbilityStub024FuzzTest(const char* data, size_t size)
471 {
472     MessageParcel requestParcel;
473     requestParcel.WriteInterfaceToken(u"location.ILocator");
474     requestParcel.WriteBuffer(data, size);
475     requestParcel.RewindRead(0);
476 
477     MessageParcel reply;
478     MessageOption option;
479 
480     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
481     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::ADD_FENCE),
482         requestParcel, reply, option);
483 
484     return true;
485 }
486 
LocatorAbilityStub025FuzzTest(const char* data, size_t size)487 bool LocatorAbilityStub025FuzzTest(const char* data, size_t size)
488 {
489     MessageParcel requestParcel;
490     requestParcel.WriteInterfaceToken(u"location.ILocator");
491     requestParcel.WriteBuffer(data, size);
492     requestParcel.RewindRead(0);
493 
494     MessageParcel reply;
495     MessageOption option;
496 
497     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
498     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::FLUSH_CACHED_LOCATIONS),
499         requestParcel, reply, option);
500 
501     return true;
502 }
503 
LocatorAbilityStub026FuzzTest(const char* data, size_t size)504 bool LocatorAbilityStub026FuzzTest(const char* data, size_t size)
505 {
506     MessageParcel requestParcel;
507     requestParcel.WriteInterfaceToken(u"location.ILocator");
508     requestParcel.WriteBuffer(data, size);
509     requestParcel.RewindRead(0);
510 
511     MessageParcel reply;
512     MessageOption option;
513 
514     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
515     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_CACHED_LOCATION_SIZE),
516         requestParcel, reply, option);
517 
518     return true;
519 }
520 
LocatorAbilityStub027FuzzTest(const char* data, size_t size)521 bool LocatorAbilityStub027FuzzTest(const char* data, size_t size)
522 {
523     MessageParcel requestParcel;
524     requestParcel.WriteInterfaceToken(u"location.ILocator");
525     requestParcel.WriteBuffer(data, size);
526     requestParcel.RewindRead(0);
527 
528     MessageParcel reply;
529     MessageOption option;
530 
531     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
532     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_CACHED_CALLBACK),
533         requestParcel, reply, option);
534 
535     return true;
536 }
537 
LocatorAbilityStub028FuzzTest(const char* data, size_t size)538 bool LocatorAbilityStub028FuzzTest(const char* data, size_t size)
539 {
540     MessageParcel requestParcel;
541     requestParcel.WriteInterfaceToken(u"location.ILocator");
542     requestParcel.WriteBuffer(data, size);
543     requestParcel.RewindRead(0);
544 
545     MessageParcel reply;
546     MessageOption option;
547 
548     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
549     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_GNSS_STATUS_CALLBACK),
550         requestParcel, reply, option);
551 
552     return true;
553 }
554 
LocatorAbilityStub029FuzzTest(const char* data, size_t size)555 bool LocatorAbilityStub029FuzzTest(const char* data, size_t size)
556 {
557     MessageParcel requestParcel;
558     requestParcel.WriteInterfaceToken(u"location.ILocator");
559     requestParcel.WriteBuffer(data, size);
560     requestParcel.RewindRead(0);
561 
562     MessageParcel reply;
563     MessageOption option;
564 
565     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
566     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_NMEA_CALLBACK),
567         requestParcel, reply, option);
568 
569     return true;
570 }
571 
LocatorAbilityStub030FuzzTest(const char* data, size_t size)572 bool LocatorAbilityStub030FuzzTest(const char* data, size_t size)
573 {
574     MessageParcel requestParcel;
575     requestParcel.WriteInterfaceToken(u"location.ILocator");
576     requestParcel.WriteBuffer(data, size);
577     requestParcel.RewindRead(0);
578 
579     MessageParcel reply;
580     MessageOption option;
581 
582     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
583     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_NMEA_CALLBACK_V9),
584         requestParcel, reply, option);
585 
586     return true;
587 }
588 
LocatorAbilityStub031FuzzTest(const char* data, size_t size)589 bool LocatorAbilityStub031FuzzTest(const char* data, size_t size)
590 {
591     MessageParcel requestParcel;
592     requestParcel.WriteInterfaceToken(u"location.ILocator");
593     requestParcel.WriteBuffer(data, size);
594     requestParcel.RewindRead(0);
595 
596     MessageParcel reply;
597     MessageOption option;
598 
599     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
600     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REMOVE_FENCE),
601         requestParcel, reply, option);
602 
603     return true;
604 }
605 
LocatorAbilityStub032FuzzTest(const char* data, size_t size)606 bool LocatorAbilityStub032FuzzTest(const char* data, size_t size)
607 {
608     MessageParcel requestParcel;
609     requestParcel.WriteInterfaceToken(u"location.ILocator");
610     requestParcel.WriteBuffer(data, size);
611     requestParcel.RewindRead(0);
612 
613     MessageParcel reply;
614     MessageOption option;
615 
616     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
617     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::SEND_COMMAND),
618         requestParcel, reply, option);
619 
620     return true;
621 }
622 
LocatorAbilityStub033FuzzTest(const char* data, size_t size)623 bool LocatorAbilityStub033FuzzTest(const char* data, size_t size)
624 {
625     MessageParcel requestParcel;
626     requestParcel.WriteInterfaceToken(u"location.ILocator");
627     requestParcel.WriteBuffer(data, size);
628     requestParcel.RewindRead(0);
629 
630     MessageParcel reply;
631     MessageOption option;
632 
633     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
634     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_CACHED_CALLBACK),
635         requestParcel, reply, option);
636 
637     return true;
638 }
639 
LocatorAbilityStub034FuzzTest(const char* data, size_t size)640 bool LocatorAbilityStub034FuzzTest(const char* data, size_t size)
641 {
642     MessageParcel requestParcel;
643     requestParcel.WriteInterfaceToken(u"location.ILocator");
644     requestParcel.WriteBuffer(data, size);
645     requestParcel.RewindRead(0);
646 
647     MessageParcel reply;
648     MessageOption option;
649 
650     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
651     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_GNSS_STATUS_CALLBACK),
652         requestParcel, reply, option);
653 
654     return true;
655 }
656 
LocatorAbilityStub035FuzzTest(const char* data, size_t size)657 bool LocatorAbilityStub035FuzzTest(const char* data, size_t size)
658 {
659     MessageParcel requestParcel;
660     requestParcel.WriteInterfaceToken(u"location.ILocator");
661     requestParcel.WriteBuffer(data, size);
662     requestParcel.RewindRead(0);
663 
664     MessageParcel reply;
665     MessageOption option;
666 
667     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
668     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_NMEA_CALLBACK),
669         requestParcel, reply, option);
670 
671     return true;
672 }
673 
LocatorAbilityStub036FuzzTest(const char* data, size_t size)674 bool LocatorAbilityStub036FuzzTest(const char* data, size_t size)
675 {
676     MessageParcel requestParcel;
677     requestParcel.WriteInterfaceToken(u"location.ILocator");
678     requestParcel.WriteBuffer(data, size);
679     requestParcel.RewindRead(0);
680 
681     MessageParcel reply;
682     MessageOption option;
683     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
684     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_NMEA_CALLBACK_V9),
685         requestParcel, reply, option);
686 
687     return true;
688 }
689 
LocatorAbilityStub037FuzzTest(const char* data, size_t size)690 bool LocatorAbilityStub037FuzzTest(const char* data, size_t size)
691 {
692     MessageParcel requestParcel;
693     requestParcel.WriteInterfaceToken(u"location.ILocator");
694     requestParcel.WriteBuffer(data, size);
695     requestParcel.RewindRead(0);
696 
697     MessageParcel reply;
698     MessageOption option;
699     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
700     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_SWITCH_CALLBACK),
701         requestParcel, reply, option);
702 
703     return true;
704 }
705 
LocatorAbilityStub038FuzzTest(const char* data, size_t size)706 bool LocatorAbilityStub038FuzzTest(const char* data, size_t size)
707 {
708     MessageParcel requestParcel;
709     requestParcel.WriteInterfaceToken(u"location.ILocator");
710     requestParcel.WriteBuffer(data, size);
711     requestParcel.RewindRead(0);
712 
713     MessageParcel reply;
714     MessageOption option;
715     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
716     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_LOCATION_ERROR),
717         requestParcel, reply, option);
718 
719     return true;
720 }
721 
LocatorAbilityStub039FuzzTest(const char* data, size_t size)722 bool LocatorAbilityStub039FuzzTest(const char* data, size_t size)
723 {
724     MessageParcel requestParcel;
725     requestParcel.WriteInterfaceToken(u"location.ILocator");
726     requestParcel.WriteBuffer(data, size);
727     requestParcel.RewindRead(0);
728 
729     MessageParcel reply;
730     MessageOption option;
731     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
732     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_LOCATION_ERROR),
733         requestParcel, reply, option);
734 
735     return true;
736 }
737 
LocatorAbilityStub040FuzzTest(const char* data, size_t size)738 bool LocatorAbilityStub040FuzzTest(const char* data, size_t size)
739 {
740     MessageParcel requestParcel;
741     requestParcel.WriteInterfaceToken(u"location.ILocator");
742     requestParcel.WriteBuffer(data, size);
743     requestParcel.RewindRead(0);
744 
745     MessageParcel reply;
746     MessageOption option;
747     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
748     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REPORT_LOCATION_ERROR),
749         requestParcel, reply, option);
750 
751     return true;
752 }
753 
LocatorAbilityStub041FuzzTest(const char* data, size_t size)754 bool LocatorAbilityStub041FuzzTest(const char* data, size_t size)
755 {
756     MessageParcel requestParcel;
757     requestParcel.WriteInterfaceToken(u"location.ILocator");
758     requestParcel.WriteBuffer(data, size);
759     requestParcel.RewindRead(0);
760 
761     MessageParcel reply;
762     MessageOption option;
763     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
764     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::ADD_GNSS_GEOFENCE),
765         requestParcel, reply, option);
766 
767     return true;
768 }
769 
LocatorAbilityStub042FuzzTest(const char* data, size_t size)770 bool LocatorAbilityStub042FuzzTest(const char* data, size_t size)
771 {
772     MessageParcel requestParcel;
773     requestParcel.WriteInterfaceToken(u"location.ILocator");
774     requestParcel.WriteBuffer(data, size);
775     requestParcel.RewindRead(0);
776 
777     MessageParcel reply;
778     MessageOption option;
779     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
780     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REMOVE_GNSS_GEOFENCE),
781         requestParcel, reply, option);
782 
783     return true;
784 }
785 
LocatorAbilityStub043FuzzTest(const char* data, size_t size)786 bool LocatorAbilityStub043FuzzTest(const char* data, size_t size)
787 {
788     MessageParcel requestParcel;
789     requestParcel.WriteInterfaceToken(u"location.ILocator");
790     requestParcel.WriteBuffer(data, size);
791     requestParcel.RewindRead(0);
792 
793     MessageParcel reply;
794     MessageOption option;
795     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
796     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::GET_GEOFENCE_SUPPORT_COORDINATE_SYSTEM_TYPE),
797         requestParcel, reply, option);
798 
799     return true;
800 }
801 
LocatorAbilityStub044FuzzTest(const char* data, size_t size)802 bool LocatorAbilityStub044FuzzTest(const char* data, size_t size)
803 {
804     MessageParcel requestParcel;
805     requestParcel.WriteInterfaceToken(u"location.ILocator");
806     requestParcel.WriteBuffer(data, size);
807     requestParcel.RewindRead(0);
808 
809     MessageParcel reply;
810     MessageOption option;
811     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
812     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::REG_LOCATING_REQUIRED_DATA_CALLBACK),
813         requestParcel, reply, option);
814 
815     return true;
816 }
817 
LocatorAbilityStub045FuzzTest(const char* data, size_t size)818 bool LocatorAbilityStub045FuzzTest(const char* data, size_t size)
819 {
820     MessageParcel requestParcel;
821     requestParcel.WriteInterfaceToken(u"location.ILocator");
822     requestParcel.WriteBuffer(data, size);
823     requestParcel.RewindRead(0);
824 
825     MessageParcel reply;
826     MessageOption option;
827     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
828     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::UNREG_LOCATING_REQUIRED_DATA_CALLBACK),
829         requestParcel, reply, option);
830     auto locatorAbility = LocatorAbility::GetInstance();
831     if (locatorAbility != nullptr) {
832         locatorAbility->RemoveUnloadTask(DEFAULT_CODE);
833     }
834     return true;
835 }
836 
LocatorAbilityStub046FuzzTest(const char* data, size_t size)837 bool LocatorAbilityStub046FuzzTest(const char* data, size_t size)
838 {
839     MessageParcel requestParcel;
840     requestParcel.WriteInterfaceToken(u"location.ILocator");
841     requestParcel.WriteBuffer(data, size);
842     requestParcel.RewindRead(0);
843 
844     MessageParcel reply;
845     MessageOption option;
846     auto ability = sptr<LocatorAbility>(new (std::nothrow) LocatorAbility());
847     ability->OnRemoteRequest(static_cast<int>(LocatorInterfaceCode::ENABLE_ABILITY_BY_USERID),
848         requestParcel, reply, option);
849     return true;
850 }
851 
852 } // namespace OHOS
853 
GeoCodeFuzzTest(const char* ch, size_t size)854 void GeoCodeFuzzTest(const char* ch, size_t size)
855 {
856     OHOS::LocatorAbilityStub018FuzzTest(ch, size);
857     OHOS::LocatorAbilityStub019FuzzTest(ch, size);
858     OHOS::LocatorAbilityStub020FuzzTest(ch, size);
859     OHOS::LocatorAbilityStub021FuzzTest(ch, size);
860     OHOS::LocatorAbilityStub022FuzzTest(ch, size);
861     OHOS::LocatorAbilityStub023FuzzTest(ch, size);
862 }
863 
SwitchFuzzTest(const char* ch, size_t size)864 void SwitchFuzzTest(const char* ch, size_t size)
865 {
866     OHOS::LocatorAbilityStub002FuzzTest(ch, size);
867     OHOS::LocatorAbilityStub006FuzzTest(ch, size);
868     OHOS::LocatorAbilityStub046FuzzTest(ch, size);
869 }
870 
871 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)872 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
873 {
874     char* ch = OHOS::ParseData(data, size);
875     if (ch != nullptr) {
876         OHOS::MockNativePermission();
877         GeoCodeFuzzTest(ch, size);
878         SwitchFuzzTest(ch, size);
879         OHOS::LocatorAbilityStub001FuzzTest(ch, size);
880         OHOS::LocatorAbilityStub003FuzzTest(ch, size);
881         OHOS::LocatorAbilityStub004FuzzTest(ch, size);
882         OHOS::LocatorAbilityStub005FuzzTest(ch, size);
883         OHOS::LocatorAbilityStub007FuzzTest(ch, size);
884         OHOS::LocatorAbilityStub008FuzzTest(ch, size);
885         OHOS::LocatorAbilityStub009FuzzTest(ch, size);
886         OHOS::LocatorAbilityStub010FuzzTest(ch, size);
887         OHOS::LocatorAbilityStub011FuzzTest(ch, size);
888         OHOS::LocatorAbilityStub012FuzzTest(ch, size);
889         OHOS::LocatorAbilityStub013FuzzTest(ch, size);
890         OHOS::LocatorAbilityStub014FuzzTest(ch, size);
891         OHOS::LocatorAbilityStub015FuzzTest(ch, size);
892         OHOS::LocatorAbilityStub016FuzzTest(ch, size);
893         OHOS::LocatorAbilityStub017FuzzTest(ch, size);
894         OHOS::LocatorAbilityStub024FuzzTest(ch, size);
895         OHOS::LocatorAbilityStub025FuzzTest(ch, size);
896         OHOS::LocatorAbilityStub026FuzzTest(ch, size);
897         OHOS::LocatorAbilityStub027FuzzTest(ch, size);
898         OHOS::LocatorAbilityStub028FuzzTest(ch, size);
899         OHOS::LocatorAbilityStub029FuzzTest(ch, size);
900         OHOS::LocatorAbilityStub030FuzzTest(ch, size);
901         OHOS::LocatorAbilityStub031FuzzTest(ch, size);
902         OHOS::LocatorAbilityStub032FuzzTest(ch, size);
903         OHOS::LocatorAbilityStub033FuzzTest(ch, size);
904         OHOS::LocatorAbilityStub034FuzzTest(ch, size);
905         OHOS::LocatorAbilityStub035FuzzTest(ch, size);
906         OHOS::LocatorAbilityStub036FuzzTest(ch, size);
907         OHOS::LocatorAbilityStub037FuzzTest(ch, size);
908         OHOS::LocatorAbilityStub038FuzzTest(ch, size);
909         OHOS::LocatorAbilityStub039FuzzTest(ch, size);
910         OHOS::LocatorAbilityStub040FuzzTest(ch, size);
911         OHOS::LocatorAbilityStub041FuzzTest(ch, size);
912         OHOS::LocatorAbilityStub042FuzzTest(ch, size);
913         OHOS::LocatorAbilityStub043FuzzTest(ch, size);
914         OHOS::LocatorAbilityStub044FuzzTest(ch, size);
915         OHOS::LocatorAbilityStub045FuzzTest(ch, size);
916         sleep(OHOS::WAIT_EVENT_TIME);
917         free(ch);
918         ch = nullptr;
919     }
920     return 0;
921 }
922 
923