• 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 "kiosk_feature_plugin_fuzzer.h"
17 
18 #include <system_ability_definition.h>
19 
20 #include "common_fuzzer.h"
21 #include "edm_ipc_interface_code.h"
22 #include "func_code.h"
23 #include "ienterprise_device_mgr.h"
24 #include "message_parcel.h"
25 #include "utils.h"
26 
27 namespace OHOS {
28 namespace EDM {
29 constexpr size_t MIN_SIZE = 24;
30 constexpr size_t WITHOUT_USERID = 0;
31 constexpr const char *WITHOUT_PERMISSION_TAG = "";
32 constexpr int32_t RANGE_DATA = 10;
33 
34 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)35 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
36 {
37     if (data == nullptr) {
38         return 0;
39     }
40     if (size < MIN_SIZE) {
41         return 0;
42     }
43     uint32_t code = EdmInterfaceCode::SET_KIOSK_FEATURE;
44     code = POLICY_FUNC_CODE(static_cast<uint32_t>(FuncOperateType::SET), code);
45     AppExecFwk::ElementName admin;
46     int32_t pos = 0;
47     int32_t stringSize = size / 2;
48     admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size));
49     admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size));
50     MessageParcel parcel;
51     parcel.WriteInterfaceToken(IEnterpriseDeviceMgrIdl::GetDescriptor());
52     parcel.WriteInt32(WITHOUT_USERID);
53     parcel.WriteString(WITHOUT_PERMISSION_TAG);
54     parcel.WriteInt32(0);
55     parcel.WriteParcelable(&admin);
56     int dataPos = 0;
57     int index = CommonFuzzer::GetU32Data(data, dataPos, size) % RANGE_DATA;
58     std::vector<int32_t> kioskFeature = { index };
59     parcel.WriteInt32Vector(kioskFeature);
60     CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
61     return 0;
62 }
63 } // namespace EDM
64 } // namespace OHOS