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 "newsmsnotify_fuzzer.h"
1711fccf17Sopenharmony_ci
1811fccf17Sopenharmony_ci#include <cstddef>
1911fccf17Sopenharmony_ci#include <cstdint>
2011fccf17Sopenharmony_ci
2111fccf17Sopenharmony_ci#include "hril_manager.h"
2211fccf17Sopenharmony_ci#include "hril_notification.h"
2311fccf17Sopenharmony_ci#include "hril_sms.h"
2411fccf17Sopenharmony_ci#include "system_ability_definition.h"
2511fccf17Sopenharmony_ci
2611fccf17Sopenharmony_ciusing namespace OHOS::Telephony;
2711fccf17Sopenharmony_cinamespace OHOS {
2811fccf17Sopenharmony_ciconstexpr int32_t SLOT_NUM = 2;
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    HRilSmsResponse response;
3911fccf17Sopenharmony_ci    int32_t offset = 0;
4011fccf17Sopenharmony_ci    response.msgRef = static_cast<int32_t>(*data + offset);
4111fccf17Sopenharmony_ci    offset += sizeof(int32_t);
4211fccf17Sopenharmony_ci    response.pdu = const_cast<char *>(NUMBER);
4311fccf17Sopenharmony_ci    response.errCode = static_cast<int32_t>(*data + offset);
4411fccf17Sopenharmony_ci
4511fccf17Sopenharmony_ci    struct ReportInfo report;
4611fccf17Sopenharmony_ci    report.error = static_cast<HRilErrNumber>(size);
4711fccf17Sopenharmony_ci    report.notifyId = HNOTI_SMS_NEW_SMS;
4811fccf17Sopenharmony_ci    report.type = HRIL_NOTIFICATION;
4911fccf17Sopenharmony_ci    HRilManager::manager_->OnSmsReport(slotId, &report, (const uint8_t *)&response, sizeof(HRilSmsResponse));
5011fccf17Sopenharmony_ci    return;
5111fccf17Sopenharmony_ci}
5211fccf17Sopenharmony_ci} // namespace OHOS
5311fccf17Sopenharmony_ci
5411fccf17Sopenharmony_ci/* Fuzzer entry point */
5511fccf17Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
5611fccf17Sopenharmony_ci{
5711fccf17Sopenharmony_ci    /* Run your code on data */
5811fccf17Sopenharmony_ci    OHOS::DoSomethingInterestingWithMyAPI(data, size);
5911fccf17Sopenharmony_ci    return 0;
6011fccf17Sopenharmony_ci}
61