1 /*
2 * Copyright (c) 2022 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 "arkressched_fuzzer.h"
17
18 #include "base/ressched/ressched_report.h"
19
20 namespace OHOS::Ace {
21 constexpr uint32_t u16m = 65535;
22 using namespace std;
veryfi(string & s,const uint8_t * data,size_t size)23 void veryfi(string& s, const uint8_t* data, size_t size)
24 {
25 bool ok = true;
26 auto ri = size % u16m;
27 for (size_t i = 0; i < ri; i++) {
28 if ((data[i] < '0' || data[i] > '9') && (data[i] < 'a' || data[i] > 'z')) {
29 ok = false;
30 break;
31 }
32 }
33 if (ri == 0 || ok == false) {
34 s = "123";
35 return;
36 }
37 s = string(reinterpret_cast<const char*>(data), ri);
38 }
39
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)40 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
41 {
42 bool result = false;
43 string s;
44 auto& resch = ResSchedReport::GetInstance();
45 veryfi(s, data, size);
46 resch.ResSchedDataReport(s.c_str());
47 resch.ResSchedDataReport(1);
48 ResSchedReportScope(s.c_str());
49 resch.OnTouchEvent(TouchType::DOWN);
50 return result;
51 }
52 }
53
54 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)55 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
56 {
57 /* Run your code on data */
58 OHOS::Ace::DoSomethingInterestingWithMyAPI(data, size);
59 return 0;
60 }
61
62