/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "install_plugin_fuzzer.h" #include #include "common_fuzzer.h" #include "edm_ipc_interface_code.h" #include "ienterprise_device_mgr.h" #include "func_code.h" #include "message_parcel.h" #include "utils.h" namespace OHOS { namespace EDM { constexpr size_t MIN_SIZE = 16; constexpr int32_t WITHOUT_USERID = 0; // Fuzzer entry point. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (data == nullptr) { return 0; } if (size < MIN_SIZE) { return 0; } int32_t pos = 0; int32_t stringSize = size / 9; for (uint32_t operateType = static_cast(FuncOperateType::GET); operateType <= static_cast(FuncOperateType::REMOVE); operateType++) { uint32_t code = EdmInterfaceCode::INSTALL; code = POLICY_FUNC_CODE(operateType, code); AppExecFwk::ElementName admin; admin.SetBundleName(CommonFuzzer::GetString(data, pos, stringSize, size)); admin.SetAbilityName(CommonFuzzer::GetString(data, pos, stringSize, size)); MessageParcel parcel; parcel.WriteInterfaceToken(IEnterpriseDeviceMgr::GetDescriptor()); parcel.WriteInt32(WITHOUT_USERID); if (operateType) { parcel.WriteParcelable(&admin); std::string path(CommonFuzzer::GetString(data, pos, stringSize, size)); std::vector realPaths = { path }; parcel.WriteStringVector(realPaths); int32_t uint32pos = 0; int32_t installParamUserId = CommonFuzzer::GetU32Data(data, uint32pos, size); parcel.WriteInt32(installParamUserId); int32_t installParamInstallFlag = CommonFuzzer::GetU32Data(data, uint32pos, size); parcel.WriteInt32(installParamInstallFlag); } else { parcel.WriteString(""); parcel.WriteInt32(0); parcel.WriteParcelable(&admin); } CommonFuzzer::OnRemoteRequestFuzzerTest(code, data, size, parcel); } return 0; } } // namespace EDM } // namespace OHOS