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