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 "disallow_add_os_account_by_user_plugin_fuzzer.h"
17
18 #include <system_ability_definition.h>
19
20 #include "common_fuzzer.h"
21 #include "edm_constants.h"
22 #include "edm_ipc_interface_code.h"
23 #include "ienterprise_device_mgr.h"
24 #include "func_code.h"
25 #include "message_parcel.h"
26 #include "utils.h"
27
28 namespace OHOS {
29 namespace EDM {
30 constexpr size_t MIN_SIZE = 16;
31 constexpr size_t WITHOUT_USERID = 0;
32
33 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)34 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
35 {
36 if (data == nullptr) {
37 return 0;
38 }
39 if (size < MIN_SIZE) {
40 return 0;
41 }
42 int32_t pos = 0;
43 int32_t stringSize = size / 12;
44 for (uint32_t operateType = static_cast<uint32_t>(FuncOperateType::GET);
45 operateType <= static_cast<uint32_t>(FuncOperateType::REMOVE); operateType++) {
46 uint32_t code = EdmInterfaceCode::DISALLOW_ADD_OS_ACCOUNT_BY_USER;
47 code = POLICY_FUNC_CODE(operateType, code);
48
49 AppExecFwk::ElementName admin;
50 admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size));
51 admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size));
52 MessageParcel parcel;
53 parcel.WriteInterfaceToken(IEnterpriseDeviceMgr::GetDescriptor());
54 parcel.WriteInt32(WITHOUT_USERID);
55 if (operateType) {
56 parcel.WriteParcelable(&admin);
57 std::vector<std::string> key {CommonFuzzer::GetString(data, pos, stringSize, size)};
58 std::vector<std::string> value {CommonFuzzer::GetString(data, pos, stringSize, size)};
59 parcel.WriteStringVector(key);
60 parcel.WriteStringVector(value);
61 } else {
62 parcel.WriteString("");
63 bool hasAdmin = CommonFuzzer::GetU32Data(data) % 2;
64 if (hasAdmin) {
65 parcel.WriteInt32(0);
66 parcel.WriteParcelable(&admin);
67 } else {
68 parcel.WriteInt32(0);
69 }
70 parcel.WriteInt32(CommonFuzzer::GetU32Data(data));
71 }
72 CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
73 }
74 return 0;
75 }
76 } // namespace EDM
77 } // namespace OHOS