• 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 "get_device_info_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 "ienterprise_device_mgr.h"
23 #include "func_code.h"
24 #include "message_parcel.h"
25 #include "utils.h"
26 
27 namespace OHOS {
28 namespace EDM {
29 constexpr size_t MIN_SIZE = 16;
30 constexpr size_t WITHOUT_USERID = 0;
31 constexpr const char *WITHOUT_PERMISSION_TAG = "";
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     uint32_t code = EdmInterfaceCode::GET_DEVICE_INFO;
43     code = POLICY_FUNC_CODE(static_cast<uint32_t>(FuncOperateType::GET), code);
44     AppExecFwk::ElementName admin;
45     int32_t pos = 0;
46     int32_t stringSize = size / 2;
47     admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size));
48     admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size));
49     MessageParcel parcel;
50     parcel.WriteInterfaceToken(IEnterpriseDeviceMgrIdl::GetDescriptor());
51     parcel.WriteInt32(WITHOUT_USERID);
52     parcel.WriteString(WITHOUT_PERMISSION_TAG);
53     parcel.WriteInt32(0);
54     parcel.WriteParcelable(&admin);
55     std::vector<std::string> deviceLabel = {
56         "deviceName",
57         "deviceSerial",
58         "simInfo",
59         "slotId",
60         "MEID",
61         "IMSI",
62         "ICCID",
63         "IMEI",
64         "invalidString",
65     };
66     int dataPos = 0;
67     int index = CommonFuzzer::GetU32Data(data, dataPos, size) % deviceLabel.size();
68     parcel.WriteString(deviceLabel[index]);
69     CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel);
70     return 0;
71 }
72 } // namespace EDM
73 } // namespace OHOS