1/* 2 * Copyright (c) 2022-2023 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#define private public 16#define protected public 17#include "security_mode_parser.h" 18#undef private 19 20#include "securitymodeparser_fuzzer.h" 21 22using namespace OHOS::MiscServices; 23namespace OHOS { 24void FuzzInitialize(const int32_t userId) 25{ 26 SecurityModeParser::GetInstance()->Initialize(userId); 27} 28 29void FuzzGetSecurityMode(const std::string &bundleName, const int32_t userId) 30{ 31 SecurityModeParser::GetInstance()->GetSecurityMode(bundleName, userId); 32} 33 34void FuzzUpdateFullModeList(const int32_t userId) 35{ 36 SecurityModeParser::GetInstance()->UpdateFullModeList(userId); 37} 38 39void FuzzParseSecurityMode(const std::string &bundleName, const int32_t userId) 40{ 41 SecurityModeParser::GetInstance()->ParseSecurityMode(bundleName, userId); 42} 43 44void FuzzIsFullMode(const std::string &bundleName) 45{ 46 SecurityModeParser::GetInstance()->IsFullMode(bundleName); 47} 48 49} // namespace OHOS 50/* Fuzzer entry point */ 51extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 52{ 53 if (data == nullptr) { 54 return 0; 55 } 56 /* Run your code on data */ 57 const int32_t userId = static_cast<int32_t>(size); 58 std::string fuzzedString(reinterpret_cast<const char *>(data), size); 59 60 OHOS::FuzzInitialize(userId); 61 OHOS::FuzzGetSecurityMode(fuzzedString, userId); 62 OHOS::FuzzUpdateFullModeList(userId); 63 OHOS::FuzzParseSecurityMode(fuzzedString, userId); 64 OHOS::FuzzIsFullMode(fuzzedString); 65 return 0; 66} 67