• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "allowed_wifi_list_plugin_fuzzer.h"
17 
18 #include <system_ability_definition.h>
19 
20 #define protected public
21 #define private public
22 #include "allowed_wifi_list_plugin.h"
23 #undef protected
24 #undef private
25 #include "common_fuzzer.h"
26 #include "edm_ipc_interface_code.h"
27 #include "func_code.h"
28 #include "get_data_template.h"
29 #include "ienterprise_device_mgr.h"
30 #include "message_parcel.h"
31 #include "plugin_manager.h"
32 #include "utils.h"
33 #include "wifi_device.h"
34 
35 namespace OHOS {
36 namespace EDM {
37 constexpr size_t MIN_SIZE = 15;
38 constexpr int32_t WITHOUT_USERID = 0;
39 constexpr int32_t WIFI_LIST_SIZE = 1;
40 
41 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)42 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
43 {
44     if (data == nullptr || size < MIN_SIZE) {
45         return 0;
46     }
47     int32_t pos = 0;
48     int32_t stringSize = size / 15;
49     for (uint32_t operateType = static_cast<uint32_t>(FuncOperateType::GET);
50         operateType <= static_cast<uint32_t>(FuncOperateType::REMOVE); operateType++) {
51         uint32_t code = EdmInterfaceCode::ALLOWED_WIFI_LIST;
52         code = POLICY_FUNC_CODE(operateType, code);
53         AppExecFwk::ElementName admin;
54         admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size));
55         admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size));
56         MessageParcel parcel;
57         parcel.WriteInterfaceToken(IEnterpriseDeviceMgrIdl::GetDescriptor());
58         parcel.WriteInt32(WITHOUT_USERID);
59         if (operateType) {
60             parcel.WriteParcelable(&admin);
61             parcel.WriteInt32(WIFI_LIST_SIZE);
62             WifiId wifiId;
63             wifiId.SetSsid(CommonFuzzer::GetString(data, pos, stringSize, size));
64             wifiId.SetBssid(CommonFuzzer::GetString(data, pos, stringSize, size));
65             std::vector<WifiId> wifiIds = { wifiId };
66             std::for_each(wifiIds.begin(), wifiIds.end(),
67                 [&](const auto wifiId) { wifiId.Marshalling(parcel); });
68         } else {
69             parcel.WriteString("");
70             parcel.WriteInt32(0);
71             parcel.WriteParcelable(&admin);
72         }
73         CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
74     }
75     AllowWifiListPlugin plugin;
76     std::string adminName = CommonFuzzer::GetString(data, pos, stringSize, size);
77     WifiId wifiId1;
78     wifiId1.SetSsid(CommonFuzzer::GetString(data, pos, stringSize, size));
79     wifiId1.SetBssid(CommonFuzzer::GetString(data, pos, stringSize, size));
80     std::vector<WifiId> policyData = { wifiId1 };
81     WifiId wifiId2;
82     wifiId2.SetSsid(CommonFuzzer::GetString(data, pos, stringSize, size));
83     wifiId2.SetBssid(CommonFuzzer::GetString(data, pos, stringSize, size));
84     std::vector<WifiId> mergeData = { wifiId2 };
85     int32_t userId = CommonFuzzer::GetU32Data(data);
86     plugin.OnAdminRemove(adminName, policyData, mergeData, userId);
87     return 0;
88 }
89 } // namespace EDM
90 } // namespace OHOS