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 "disallowed_sim_plugin_fuzzer.h"
17
18 #include <system_ability_definition.h>
19
20 #define protected public
21 #define private public
22 #include "disallowed_sim_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 "usb_device_id.h"
33 #include "utils.h"
34
35 namespace OHOS {
36 namespace EDM {
37 constexpr size_t MIN_SIZE = 16;
38 constexpr int32_t WITHOUT_USERID = 0;
39
40 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
42 {
43 if (data == nullptr) {
44 return 0;
45 }
46 if (size < MIN_SIZE) {
47 return 0;
48 }
49 int32_t pos = 0;
50 int32_t stringSize = size / 7;
51 int32_t id = size % 3;
52 for (uint32_t operateType = static_cast<uint32_t>(FuncOperateType::GET);
53 operateType <= static_cast<uint32_t>(FuncOperateType::REMOVE); operateType++) {
54 uint32_t code = EdmInterfaceCode::DISALLOWED_SIM;
55 code = POLICY_FUNC_CODE(operateType, code);
56
57 AppExecFwk::ElementName admin;
58 admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size));
59 admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size));
60 MessageParcel parcel;
61 parcel.WriteInterfaceToken(IEnterpriseDeviceMgrIdl::GetDescriptor());
62 parcel.WriteInt32(WITHOUT_USERID);
63 if (operateType) {
64 parcel.WriteParcelable(&admin);
65 parcel.WriteInt32(id);
66 } else {
67 parcel.WriteString("");
68 parcel.WriteInt32(0);
69 parcel.WriteParcelable(&admin);
70 parcel.WriteInt32(id);
71 }
72 CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
73 }
74
75 DisallowedSimPlugin plugin;
76 std::string adminName = CommonFuzzer::GetString(data, pos, stringSize, size);
77 uint32_t policyData = CommonFuzzer::GetU32Data(data);
78 uint32_t mergeData = CommonFuzzer::GetU32Data(data);
79 int32_t userId = CommonFuzzer::GetU32Data(data);
80 plugin.OnAdminRemove(adminName, policyData, mergeData, userId);
81 return 0;
82 }
83 } // namespace EDM
84 } // namespace OHOS