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 "common_fuzzer.h"
19 #include "edm_ipc_interface_code.h"
20 #include "func_code.h"
21 #include "get_data_template.h"
22 #include "message_parcel.h"
23 #define private public
24 #include "admin_policies_storage_rdb.h"
25 #undef private
26 #include "ienterprise_device_mgr.h"
27
28 namespace OHOS {
29 namespace EDM {
30 constexpr size_t MIN_SIZE = 64;
31
32 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
34 {
35 if (data == nullptr) {
36 return 0;
37 }
38 if (size < MIN_SIZE) {
39 return 0;
40 }
41 g_data = data;
42 g_size = size;
43 g_pos = 0;
44
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
62 std::vector<std::string> permissions = { fuzzString };
63
64 adminPoliciesStorageRdb->InsertAdmin(userId, admin);
65 adminPoliciesStorageRdb->UpdateAdmin(userId, admin);
66 adminPoliciesStorageRdb->CreateInsertValuesBucket(userId, admin);
67
68 std::string packageName(reinterpret_cast<const char*>(data), size);
69 adminPoliciesStorageRdb->DeleteAdmin(userId, packageName);
70
71 adminPoliciesStorageRdb->UpdateEntInfo(userId, packageName, entInfo);
72
73 std::vector<ManagedEvent> managedEvents = {event};
74 adminPoliciesStorageRdb->UpdateManagedEvents(userId, packageName, managedEvents);
75
76 std::string str(reinterpret_cast<const char*>(data), size);
77 Json::Value json;
78 json["test"] = str;
79 adminPoliciesStorageRdb->ConvertStrToJson(str, json);
80 return 0;
81 }
82 } // namespace EDM
83 } // namespace OHOS