1060ff233Sopenharmony_ci/*
2060ff233Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License.
5060ff233Sopenharmony_ci * You may obtain a copy of the License at
6060ff233Sopenharmony_ci *
7060ff233Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8060ff233Sopenharmony_ci *
9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and
13060ff233Sopenharmony_ci * limitations under the License.
14060ff233Sopenharmony_ci */
15060ff233Sopenharmony_ci
16060ff233Sopenharmony_ci#include "softbusadapterrange_fuzzer.h"
17060ff233Sopenharmony_ci
18060ff233Sopenharmony_ci#include <securec.h>
19060ff233Sopenharmony_ci#include "softbus_adapter_range.h"
20060ff233Sopenharmony_ci
21060ff233Sopenharmony_cinamespace OHOS {
22060ff233Sopenharmony_cistatic void SoftBusAdapterRangeFuzzTest(const uint8_t* data, size_t size)
23060ff233Sopenharmony_ci{
24060ff233Sopenharmony_ci    if (size < sizeof(SoftBusRangeParam)) {
25060ff233Sopenharmony_ci        return;
26060ff233Sopenharmony_ci    }
27060ff233Sopenharmony_ci
28060ff233Sopenharmony_ci    SoftBusRangeParam rangeParam = {0};
29060ff233Sopenharmony_ci    if (memcpy_s(&rangeParam, sizeof(SoftBusRangeParam), data, sizeof(SoftBusRangeParam)) != EOK) {
30060ff233Sopenharmony_ci        return;
31060ff233Sopenharmony_ci    }
32060ff233Sopenharmony_ci
33060ff233Sopenharmony_ci    rangeParam.modelId[SOFTBUS_MODEL_ID_LEN - 1] = '\0';
34060ff233Sopenharmony_ci    rangeParam.subModelId[SOFTBUS_SUB_MODEL_ID_LEN - 1] = '\0';
35060ff233Sopenharmony_ci    rangeParam.newModelId[SOFTBUS_NEW_MODEL_ID_LEN - 1] = '\0';
36060ff233Sopenharmony_ci    rangeParam.identity[SOFTBUS_DEV_IDENTITY_LEN - 1] = '\0';
37060ff233Sopenharmony_ci
38060ff233Sopenharmony_ci    int32_t range = 0;
39060ff233Sopenharmony_ci    SoftBusBleRange(&rangeParam, &range);
40060ff233Sopenharmony_ci
41060ff233Sopenharmony_ci    int8_t power = 0;
42060ff233Sopenharmony_ci    SoftBusGetBlePower(&power);
43060ff233Sopenharmony_ci}
44060ff233Sopenharmony_ci}
45060ff233Sopenharmony_ci
46060ff233Sopenharmony_ci/* Fuzzer entry point */
47060ff233Sopenharmony_ciextern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
48060ff233Sopenharmony_ci{
49060ff233Sopenharmony_ci    if (data == nullptr || size < sizeof(int32_t)) {
50060ff233Sopenharmony_ci        return 0;
51060ff233Sopenharmony_ci    }
52060ff233Sopenharmony_ci    /* Run your code on data */
53060ff233Sopenharmony_ci    OHOS::SoftBusAdapterRangeFuzzTest(data, size);
54060ff233Sopenharmony_ci    return 0;
55060ff233Sopenharmony_ci}
56