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 "fuzz_common.h" 17 18namespace OHOS { 19namespace AccessControl { 20namespace SandboxManager { 21namespace { 22const uint32_t POLICY_PATH_LIMIT = 4095; 23const uint64_t POLICY_VECTOR_SIZE_LIMIT = 50; 24}; 25void PolicyInfoRandomGenerator::GeneratePolicyInfo(PolicyInfo &policyInfo) 26{ 27 policyInfo.mode = GetData<uint8_t>() % 3 + 1; // 3 is RW 28 GenerateString(policyInfo.path); 29} 30 31void PolicyInfoRandomGenerator::GeneratePolicyInfoVec(std::vector<PolicyInfo> &policyInfoVec) 32{ 33 uint32_t size = GetData<uint32_t>() % POLICY_VECTOR_SIZE_LIMIT; 34 policyInfoVec.clear(); 35 for (uint32_t i = 0; i < size; ++i) { 36 PolicyInfo policyInfo; 37 GeneratePolicyInfo(policyInfo); 38 policyInfoVec.push_back(policyInfo); 39 } 40} 41 42void PolicyInfoRandomGenerator::GenerateString(std::string &str) 43{ 44 uint32_t length = GetData<uint32_t>() % POLICY_PATH_LIMIT; 45 str = "/"; 46 for (uint32_t i = 1; i < length; ++i) { 47 str += GetData<char>(); 48 } 49} 50 51void PolicyInfoRandomGenerator::GenerateStringVec(std::vector<std::string> &strVec) 52{ 53 uint32_t size = GetData<uint32_t>() % POLICY_VECTOR_SIZE_LIMIT; 54 strVec.clear(); 55 for (uint32_t i = 0; i < size; ++i) { 56 std::string str; 57 GenerateString(str); 58 strVec.push_back(str); 59 } 60} 61} 62} 63}