• 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 "admin_policies_storage_rdb_fuzzer.h"
17 
18 #include "cJSON.h"
19 #include "common_fuzzer.h"
20 #include "edm_ipc_interface_code.h"
21 #include "func_code.h"
22 #include "get_data_template.h"
23 #include "message_parcel.h"
24 #define private public
25 #include "admin_policies_storage_rdb.h"
26 #undef private
27 #include "ienterprise_device_mgr.h"
28 
29 namespace OHOS {
30 namespace EDM {
31 constexpr size_t MIN_SIZE = 64;
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     g_data = data;
43     g_size = size;
44     g_pos = 0;
45     std::shared_ptr<AdminPoliciesStorageRdb> adminPoliciesStorageRdb = AdminPoliciesStorageRdb::GetInstance();
46     int32_t userId = CommonFuzzer::GetU32Data(data);
47     std::string fuzzString(reinterpret_cast<const char*>(data), size);
48     ManagedEvent event = GetData<ManagedEvent>();
49     Admin admin;
50     AdminInfo fuzzAdminInfo;
51     EntInfo entInfo;
52     entInfo.enterpriseName = fuzzString;
53     entInfo.description = fuzzString;
54     fuzzAdminInfo.packageName_ = fuzzString;
55     fuzzAdminInfo.className_ = fuzzString;
56     fuzzAdminInfo.entInfo_ = entInfo;
57     fuzzAdminInfo.permission_ = { fuzzString };
58     fuzzAdminInfo.managedEvents_ = { event };
59     fuzzAdminInfo.parentAdminName_ = fuzzString;
60     admin.adminInfo_ = fuzzAdminInfo;
61     std::vector<std::string> permissions = { fuzzString };
62     adminPoliciesStorageRdb->InsertAdmin(userId, admin);
63     adminPoliciesStorageRdb->UpdateAdmin(userId, admin);
64     adminPoliciesStorageRdb->CreateInsertValuesBucket(userId, admin);
65     std::string packageName(reinterpret_cast<const char*>(data), size);
66     std::string currentParentName = fuzzString;
67     std::string targetParentName = fuzzString;
68     std::string stringInfo = fuzzString;
69     std::vector<std::string> info = { fuzzString };
70     adminPoliciesStorageRdb->DeleteAdmin(userId, packageName);
71     adminPoliciesStorageRdb->UpdateEntInfo(userId, packageName, entInfo);
72     std::vector<ManagedEvent> managedEvents = {event};
73     adminPoliciesStorageRdb->UpdateManagedEvents(userId, packageName, managedEvents);
74     adminPoliciesStorageRdb->ReplaceAdmin(packageName, userId, admin);
75     adminPoliciesStorageRdb->UpdateParentName(packageName, currentParentName, targetParentName);
76     adminPoliciesStorageRdb->SetAdminStringInfo(stringInfo, info);
77     std::shared_ptr<NativeRdb::ResultSet> resultSet;
78     std::shared_ptr<Admin> item = std::make_shared<Admin>(admin);
79     adminPoliciesStorageRdb->SetAdminItems(resultSet, item);
80     adminPoliciesStorageRdb->SetManagedEventStr(resultSet, item);
81     adminPoliciesStorageRdb->QueryAllAdmin();
82     return 0;
83 }
84 } // namespace EDM
85 } // namespace OHOS