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 "reportmanager_fuzzer.h"
17
18 #include "i_locator_callback.h"
19 #include "location.h"
20 #include "locator_callback_host.h"
21 #include "report_manager.h"
22 #include "request.h"
23
24 namespace OHOS {
25 using namespace OHOS::Location;
26 const int MIN_DATA_LEN = 5;
ReportManagerFuzzerTest(const uint8_t * data,size_t size)27 bool ReportManagerFuzzerTest(const uint8_t* data, size_t size)
28 {
29 if (size < MIN_DATA_LEN) {
30 return true;
31 }
32 std::shared_ptr<ReportManager> reportManager =
33 DelayedSingleton<ReportManager>::GetInstance();
34 if (reportManager == nullptr) {
35 return false;
36 }
37 std::unique_ptr<OHOS::Location::Location> location =
38 std::make_unique<OHOS::Location::Location>();
39 auto locatorCallbackHostForTest =
40 sptr<LocatorCallbackHost>(new (std::nothrow) LocatorCallbackHost());
41 sptr<ILocatorCallback> locatorCallback =
42 sptr<ILocatorCallback>(locatorCallbackHostForTest);
43 int index = 0;
44 int type = data[index++];
45 int result = data[index++];
46 reportManager->ReportRemoteCallback(locatorCallback, type, result);
47 std::shared_ptr<Request> request = std::make_shared<Request>();
48 reportManager->ResultCheck(location, request);
49 reportManager->SetLastLocation(location);
50 reportManager->GetLastLocation();
51 pid_t uid = data[index++];
52 uint32_t tokenId = data[index++];
53 uint32_t firstTokenId = data[index++];
54 reportManager->GetPermittedLocation(uid, tokenId, firstTokenId, location);
55 reportManager->UpdateRandom();
56 return true;
57 }
58 }
59
60 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)61 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
62 {
63 /* Run your code on data */
64 OHOS::ReportManagerFuzzerTest(data, size);
65 return 0;
66 }