111fccf17Sopenharmony_ci/* 211fccf17Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 311fccf17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 411fccf17Sopenharmony_ci * you may not use this file except in compliance with the License. 511fccf17Sopenharmony_ci * You may obtain a copy of the License at 611fccf17Sopenharmony_ci * 711fccf17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 811fccf17Sopenharmony_ci * 911fccf17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1011fccf17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1111fccf17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1211fccf17Sopenharmony_ci * See the License for the specific language governing permissions and 1311fccf17Sopenharmony_ci * limitations under the License. 1411fccf17Sopenharmony_ci */ 1511fccf17Sopenharmony_ci 1611fccf17Sopenharmony_ci#include "callemergencynotice_fuzzer.h" 1711fccf17Sopenharmony_ci 1811fccf17Sopenharmony_ci#include <cstddef> 1911fccf17Sopenharmony_ci#include <cstdint> 2011fccf17Sopenharmony_ci 2111fccf17Sopenharmony_ci#include "hril_call.h" 2211fccf17Sopenharmony_ci#include "hril_manager.h" 2311fccf17Sopenharmony_ci#include "hril_notification.h" 2411fccf17Sopenharmony_ci#include "system_ability_definition.h" 2511fccf17Sopenharmony_ci 2611fccf17Sopenharmony_ciusing namespace OHOS::Telephony; 2711fccf17Sopenharmony_cinamespace OHOS { 2811fccf17Sopenharmony_ciconstexpr int32_t SLOT_NUM = 3; 2911fccf17Sopenharmony_ciconstexpr const char *NUMBER = "123"; 3011fccf17Sopenharmony_ci 3111fccf17Sopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) 3211fccf17Sopenharmony_ci{ 3311fccf17Sopenharmony_ci if (data == nullptr || size == 0) { 3411fccf17Sopenharmony_ci return; 3511fccf17Sopenharmony_ci } 3611fccf17Sopenharmony_ci 3711fccf17Sopenharmony_ci int32_t slotId = static_cast<int32_t>(*data % SLOT_NUM); 3811fccf17Sopenharmony_ci HRilErrNumber error = static_cast<HRilErrNumber>(size); 3911fccf17Sopenharmony_ci HRilEmergencyInfo info; 4011fccf17Sopenharmony_ci int32_t offset = 0; 4111fccf17Sopenharmony_ci info.index = static_cast<int32_t>(*data + offset); 4211fccf17Sopenharmony_ci offset += sizeof(int32_t); 4311fccf17Sopenharmony_ci info.total = static_cast<int32_t>(*data + offset); 4411fccf17Sopenharmony_ci offset += sizeof(int32_t); 4511fccf17Sopenharmony_ci info.eccNum = const_cast<char *>(NUMBER); 4611fccf17Sopenharmony_ci info.category = static_cast<int32_t>(*data + offset); 4711fccf17Sopenharmony_ci offset += sizeof(int32_t); 4811fccf17Sopenharmony_ci info.simpresent = static_cast<int32_t>(*data + offset); 4911fccf17Sopenharmony_ci offset += sizeof(int32_t); 5011fccf17Sopenharmony_ci info.mcc = const_cast<char *>(NUMBER); 5111fccf17Sopenharmony_ci info.abnormalService = static_cast<int32_t>(*data + offset); 5211fccf17Sopenharmony_ci struct ReportInfo report; 5311fccf17Sopenharmony_ci report.error = error; 5411fccf17Sopenharmony_ci report.notifyId = HNOTI_CALL_EMERGENCY_NUMBER_REPORT; 5511fccf17Sopenharmony_ci report.type = HRIL_NOTIFICATION; 5611fccf17Sopenharmony_ci HRilManager::manager_->OnCallReport(slotId, &report, (const uint8_t *)&info, sizeof(HRilEmergencyInfo)); 5711fccf17Sopenharmony_ci return; 5811fccf17Sopenharmony_ci} 5911fccf17Sopenharmony_ci} // namespace OHOS 6011fccf17Sopenharmony_ci 6111fccf17Sopenharmony_ci/* Fuzzer entry point */ 6211fccf17Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 6311fccf17Sopenharmony_ci{ 6411fccf17Sopenharmony_ci /* Run your code on data */ 6511fccf17Sopenharmony_ci OHOS::DoSomethingInterestingWithMyAPI(data, size); 6611fccf17Sopenharmony_ci return 0; 6711fccf17Sopenharmony_ci} 68