• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "mechbodycontrollerutils_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <cstring>
21 #include <fuzzer/FuzzedDataProvider.h>
22 #include <string>
23 
24 #include "mechbody_controller_utils.h"
25 
26 namespace OHOS {
27 using namespace OHOS::MechBodyController;
GetAnonymStrFuzzTest(const uint8_t * data,size_t size)28 void GetAnonymStrFuzzTest(const uint8_t *data, size_t size)
29 {
30     if ((data == nullptr) || (size == 0)) {
31         return;
32     }
33 
34     FuzzedDataProvider fdp(data, size);
35     std::string value = fdp.ConsumeRandomLengthString();
36 
37     GetAnonymStr(value);
38 }
39 
GetAnonymInt32FuzzTest(const uint8_t * data,size_t size)40 void GetAnonymInt32FuzzTest(const uint8_t *data, size_t size)
41 {
42     if ((data == nullptr) || (size == 0)) {
43         return;
44     }
45 
46     FuzzedDataProvider fdp(data, size);
47     int32_t value = fdp.ConsumeIntegral<int32_t>();
48 
49     GetAnonymInt32(value);
50 }
51 
GetAnonymUint32FuzzTest(const uint8_t * data,size_t size)52 void GetAnonymUint32FuzzTest(const uint8_t *data, size_t size)
53 {
54     if ((data == nullptr) || (size == 0)) {
55         return;
56     }
57 
58     FuzzedDataProvider fdp(data, size);
59     uint32_t value = fdp.ConsumeIntegral<uint32_t>();
60 
61     GetAnonymUint32(value);
62 }
63 }
64 
65 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)66 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
67 {
68     /* Run your code on data */
69     OHOS::GetAnonymStrFuzzTest(data, size);
70     OHOS::GetAnonymInt32FuzzTest(data, size);
71     OHOS::GetAnonymUint32FuzzTest(data, size);
72     return 0;
73 }