• 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 "disallowed_nearlink_protocols_plugin_fuzzer.h"
17 
18 #include "disallowed_nearlink_protocols_plugin.h"
19 
20 #include "common_fuzzer.h"
21 #include "message_parcel.h"
22 
23 namespace OHOS {
24 namespace EDM {
25 constexpr size_t MIN_SIZE = 10;
26 
27 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
29 {
30     if (data == nullptr) {
31         return 0;
32     }
33     if (size < MIN_SIZE) {
34         return 0;
35     }
36 
37     int32_t pos = 0;
38     int32_t stringSize = size / 3;
39     DisallowedNearlinkProtocolsPlugin plugin;
40     std::string policyData = CommonFuzzer::GetString(data, pos, stringSize, size);
41     MessageParcel requestData;
42     requestData.WriteString(CommonFuzzer::GetString(data, pos, stringSize, size));
43     MessageParcel reply;
44     reply.WriteString("");
45     int32_t intData = CommonFuzzer::GetU32Data(data);
46     std::vector<int32_t> intDataVector = {intData};
47     std::vector<int32_t> currentData = {intData};
48     std::vector<int32_t> mergeData = {intData};
49     int32_t userId = CommonFuzzer::GetU32Data(data);
50     std::string adminName = CommonFuzzer::GetString(data, pos, stringSize, size);
51 
52     plugin.OnGetPolicy(policyData, requestData, reply, userId);
53     plugin.OnSetPolicy(intDataVector, currentData, mergeData, userId);
54     plugin.OnGetPolicy(policyData, requestData, reply, userId);
55     plugin.OnAdminRemove(adminName, intDataVector, mergeData, userId);
56     plugin.OnRemovePolicy(intDataVector, currentData, mergeData, userId);
57     bool isGlobalChanged = CommonFuzzer::GetU32Data(data) % 2;
58     plugin.OnChangedPolicyDone(isGlobalChanged);
59     return 0;
60 }
61 } // namespace EDM
62 } // namespace OHOS