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