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 = 4;
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 uint32_t tokenId = data[index++];
52 uint32_t firstTokenId = data[index++];
53 reportManager->GetPermittedLocation(tokenId, firstTokenId, location);
54 reportManager->UpdateRandom();
55 return true;
56 }
57 }
58
59 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)60 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
61 {
62 /* Run your code on data */
63 OHOS::ReportManagerFuzzerTest(data, size);
64 return 0;
65 }