• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_napi.h"
21 #include "request.h"
22 
23 namespace OHOS {
24     using namespace OHOS::Location;
25     const int MIN_DATA_LEN = 6;
ReportManagerFuzzerTest(const uint8_t * data,size_t size)26     bool ReportManagerFuzzerTest(const uint8_t* data, size_t size)
27     {
28         if (size < MIN_DATA_LEN) {
29             return true;
30         }
31         auto reportManager =
32             ReportManager::GetInstance();
33         std::unique_ptr<OHOS::Location::Location> location =
34             std::make_unique<OHOS::Location::Location>();
35         auto locatorCallbackHostForTest =
36             sptr<LocatorCallbackNapi>(new (std::nothrow) LocatorCallbackNapi());
37         sptr<ILocatorCallback> locatorCallback =
38             sptr<ILocatorCallback>(locatorCallbackHostForTest);
39         int index = 0;
40         int type = data[index++];
41         int result = data[index++];
42         reportManager->ReportRemoteCallback(locatorCallback, type, result);
43         std::shared_ptr<Request> request = std::make_shared<Request>();
44         request->SetUid(data[index++]);
45         request->SetTokenId(data[index++]);
46         request->SetFirstTokenId(data[index++]);
47         request->SetTokenIdEx(data[index++]);
48         reportManager->OnReportLocation(location, "gps");
49         reportManager->ResultCheck(location, request);
50         reportManager->UpdateCacheLocation(location, "gps");
51         reportManager->GetLastLocation();
52         reportManager->GetCacheLocation(request);
53         reportManager->GetPermittedLocation(request, location);
54         reportManager->UpdateRandom();
55         reportManager->IsRequestFuse(request);
56         reportManager->UpdateLocationByRequest(0, 0, location);
57         reportManager->IsAppBackground("1021", 0, 0, 0, 0);
58         reportManager->IsCacheGnssLocationValid();
59         reportManager->ApproximatelyLocation(location, request);
60         std::unique_ptr<std::list<std::shared_ptr<Request>>> deadRequests;
61         reportManager->ProcessRequestForReport(request, deadRequests, location, "gps");
62         reportManager->ReportLocationByCallback(request, location);
63         reportManager->WriteNetWorkReportEvent("gps", request, location);
64         reportManager->ExecuteReportProcess(request, location, "gps");
65         reportManager->ExecuteLocationProcess(request, location);
66         reportManager->UpdateLastLocation(location);
67         reportManager->LocationReportDelayTimeCheck(location, request);
68         return true;
69     }
70 }
71 
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75     /* Run your code on data */
76     OHOS::ReportManagerFuzzerTest(data, size);
77     return 0;
78 }