1/*
2 * Copyright (C) 2024 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
16#include "commonutil_fuzzer.h"
17
18#include <cstddef>
19#include <cstdint>
20#include <unistd.h>
21#include "securec.h"
22#include "common_util.h"
23
24namespace OHOS {
25namespace Wifi {
26constexpr size_t DHCP_SLEEP_1 = 2;
27constexpr size_t U32_AT_SIZE_ZERO = 4;
28
29void CommonUtilFuzzTest(const uint8_t* data, size_t size)
30{
31    uint32_t index = 0;
32    char buf[] = {"aabbcc"};
33    size_t bufSize = static_cast<uint32_t>(data[index++]);
34    Tmspsec();
35    Tmspusec();
36    LeftTrim(buf);
37    RightTrim(buf);
38    TrimString(buf);
39    RemoveSpaceCharacters(buf, bufSize);
40}
41
42void GetFilePathTest(const uint8_t* data, size_t size)
43{
44    const char *fileName = "wlan0";
45    (void)GetFilePath(fileName);
46}
47
48void GetLeaseFileTest(const uint8_t* data, size_t size)
49{
50    const char *fileName = "wlan0";
51    const char *ifname = "wlan1";
52    (void)GetLeaseFile(fileName, ifname);
53}
54
55void CreatePathTest(const uint8_t* data, size_t size)
56{
57    const char *fileName = "wlan0";
58    (void)CreatePath(fileName);
59}
60
61/* Fuzzer entry point */
62extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
63{
64    if ((data == nullptr) || (size <= OHOS::Wifi::U32_AT_SIZE_ZERO)) {
65        return 0;
66    }
67    sleep(DHCP_SLEEP_1);
68    OHOS::Wifi::CommonUtilFuzzTest(data, size);
69    OHOS::Wifi::GetFilePathTest(data, size);
70    OHOS::Wifi::GetLeaseFileTest(data, size);
71    OHOS::Wifi::CreatePathTest(data, size);
72    return 0;
73}
74}  // namespace Wifi
75}  // namespace OHOS
76