• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "arkuiformrenderimpl_fuzzer.h"
17 
18 #define private public
19 #define protected public
20 #include "form_render/include/form_renderer_delegate_impl.h"
21 #include "form_render/include/form_renderer_dispatcher_impl.h"
22 #undef private
23 #undef protected
24 
25 namespace OHOS::Ace {
26 const uint32_t u16m = 65535;
DelegateImplAPI(const std::string data,size_t size)27 bool DelegateImplAPI(const std::string data, size_t size)
28 {
29     FormRendererDelegateImpl delegateImpl;
30     std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode;
31     OHOS::AppExecFwk::FormJsInfo formJsInfo;
32     AAFwk::Want want;
33     delegateImpl.OnSurfaceCreate(surfaceNode, formJsInfo, want);
34     delegateImpl.OnActionEvent(data);
35     delegateImpl.OnError(data, data);
36     return true;
37 }
38 
DispatcherImplAPI(const std::string data,size_t size)39 bool DispatcherImplAPI(const std::string data, size_t size)
40 {
41     std::shared_ptr<UIContent> uiContent;
42     FormRendererDispatcherImpl dispatcherImpl(uiContent, nullptr);
43     std::shared_ptr<OHOS::MMI::PointerEvent> pointEvent;
44     dispatcherImpl.DispatchPointerEvent(pointEvent);
45     dispatcherImpl.SetAllowUpdate(true);
46     dispatcherImpl.IsAllowUpdate();
47     return true;
48 }
49 }
50 
51 using namespace OHOS;
52 using namespace OHOS::Ace;
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
55 {
56     auto ri = size % u16m;
57     std::string str(reinterpret_cast<const char*>(data), ri);
58     /* Run your code on data */
59     DelegateImplAPI(str, size);
60     DispatcherImplAPI(str, size);
61     return 0;
62 }
63