• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 namespace OHOS {
25 namespace DHCP {
26 constexpr size_t DHCP_SLEEP_1 = 2;
27 constexpr size_t U32_AT_SIZE_ZERO = 4;
28 
CommonUtilFuzzTest(const uint8_t * data,size_t size)29 void 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     TrimString(buf);
37     RemoveSpaceCharacters(buf, bufSize);
38 }
39 
GetFilePathTest(const uint8_t * data,size_t size)40 void GetFilePathTest(const uint8_t* data, size_t size)
41 {
42     const char *fileName = "wlan0";
43     (void)GetFilePath(fileName);
44 }
45 
CreatePathTest(const uint8_t * data,size_t size)46 void CreatePathTest(const uint8_t* data, size_t size)
47 {
48     const char *fileName = "wlan0";
49     (void)CreatePath(fileName);
50 }
51 
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
54 {
55     if ((data == nullptr) || (size <= OHOS::DHCP::U32_AT_SIZE_ZERO)) {
56         return 0;
57     }
58     sleep(DHCP_SLEEP_1);
59     OHOS::DHCP::CommonUtilFuzzTest(data, size);
60     OHOS::DHCP::GetFilePathTest(data, size);
61     OHOS::DHCP::CreatePathTest(data, size);
62     return 0;
63 }
64 }  // namespace DHCP
65 }  // namespace OHOS
66