• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "location_policy_plugin_fuzzer.h"
17 
18 #include <system_ability_definition.h>
19 
20 #define protected public
21 #define private public
22 #include "location_policy_plugin.h"
23 #undef protected
24 #undef private
25 #include "common_fuzzer.h"
26 #include "edm_ipc_interface_code.h"
27 #include "ienterprise_device_mgr.h"
28 #include "func_code.h"
29 #include "message_parcel.h"
30 #include "utils.h"
31 #include "location_policy.h"
32 
33 namespace OHOS {
34 namespace EDM {
35 constexpr size_t MIN_SIZE = 5;
36 
37 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)38 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
39 {
40     if (data == nullptr) {
41         return 0;
42     }
43     if (size < MIN_SIZE) {
44         return 0;
45     }
46     int32_t stringSize = size / 2;
47     int32_t pos = 0;
48 
49     LocationPolicyPlugin plugin;
50     int32_t currentData = CommonFuzzer::GetU32Data(data);
51     int32_t mergeData = static_cast<int32_t>(LocationPolicy::DEFAULT_LOCATION_SERVICE);
52     int32_t userId = CommonFuzzer::GetU32Data(data);
53     int32_t policyData = CommonFuzzer::GetU32Data(data);
54     std::string adminName = CommonFuzzer::GetString(data, pos, stringSize, size);
55 
56     int32_t status = static_cast<int32_t>(LocationPolicy::DEFAULT_LOCATION_SERVICE);
57     plugin.OnSetPolicy(status, currentData, mergeData, userId);
58     status = static_cast<int32_t>(LocationPolicy::DISALLOW_LOCATION_SERVICE);
59     plugin.OnSetPolicy(status, currentData, mergeData, userId);
60     status = static_cast<int32_t>(LocationPolicy::FORCE_OPEN_LOCATION_SERVICE);
61     plugin.OnSetPolicy(status, currentData, mergeData, userId);
62     plugin.SetDefaultLocationPolicy();
63     plugin.OnAdminRemove(adminName, policyData, mergeData, userId);
64     return 0;
65 }
66 } // namespace EDM
67 } // namespace OHOS