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 <cstring>
17 #include <securec.h>
18
19 #define private public
20 #include "aafwk_app_mgr_client_adapter_impl.h"
21 #include "aafwk_browser_client_adapter_impl.h"
22 #include "aafwk_browser_host_impl.h"
23 #include "aafwk_render_scheduler_impl.h"
24 #undef private
25
26 #include "aafwk_browser_client_adapter.h"
27 #include "aafwk_render_scheduler_host_adapter.h"
28 #include "app_mgr_client.h"
29 #include "ibrowser.h"
30 #include "iconsumer_surface.h"
31 #include "iremote_proxy.h"
32 #include "irender_scheduler.h"
33 #include "ohos_adapter_helper.h"
34
35 using namespace OHOS::NWeb;
36
37 namespace OHOS {
38 class MockBrowserClient : public BrowserClient {
39 explicit MockBrowserClient(const sptr<IRemoteObject>& impl);
40
41 sptr<IRemoteObject> QueryRenderSurface(int32_t surface_id);
42
43 void ReportThread(int32_t status, int32_t process_id, int32_t thread_id, int32_t role);
44
45 void PassSurface(sptr<Surface> surface, int64_t surface_id);
46
47 void DestroyRenderSurface(int32_t surface_id);
48 };
49
QueryRenderSurface(int32_t surface_id)50 sptr<IRemoteObject> MockBrowserClient::QueryRenderSurface(int32_t surface_id)
51 {
52 (void)surface_id;
53 return nullptr;
54 }
55
ReportThread(int32_t status,int32_t process_id,int32_t thread_id,int32_t role)56 void MockBrowserClient::ReportThread(int32_t status, int32_t process_id, int32_t thread_id, int32_t role)
57 {
58 (void)status;
59 (void)process_id;
60 (void)thread_id;
61 (void)role;
62 }
63
PassSurface(sptr<Surface> surface,int64_t surface_id)64 void MockBrowserClient::PassSurface(sptr<Surface> surface, int64_t surface_id)
65 {
66 (void)surface;
67 (void)surface_id;
68 }
69
DestroyRenderSurface(int32_t surface_id)70 void MockBrowserClient::DestroyRenderSurface(int32_t surface_id)
71 {
72 (void)surface_id;
73 }
74
AafwkBrowserClientAdapterFuzzTest(const uint8_t * data,size_t size)75 bool AafwkBrowserClientAdapterFuzzTest(const uint8_t* data, size_t size)
76 {
77 sptr<IRemoteObject> impl;
78 auto client = new BrowserClient(impl);
79 int32_t surface_id = 0;
80 client->QueryRenderSurface(surface_id);
81 int32_t status = 0;
82 int32_t process_id = 0;
83 int32_t thread_id = 0;
84 int32_t role = 0;
85 sptr<Surface> surface;
86 client->ReportThread(status, process_id, thread_id, role);
87 client->PassSurface(surface, surface_id);
88 client->DestroyRenderSurface(surface_id);
89
90 std::shared_ptr<AafwkBrowserClientAdapterImpl> clientAdapter = std::make_shared<AafwkBrowserClientAdapterImpl>();
91 clientAdapter->QueryRenderSurface(surface_id);
92 ResSchedStatusAdapter newstatus = ResSchedStatusAdapter::THREAD_CREATED;
93 ResSchedRoleAdapter newrole = ResSchedRoleAdapter::USER_INTERACT;
94 clientAdapter->ReportThread(newstatus, process_id, thread_id, newrole);
95 clientAdapter->PassSurface(surface_id);
96 clientAdapter->DestroyRenderSurface(surface_id);
97 return true;
98 }
99 } // namespace OHOS
100
101 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)102 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
103 {
104 /* Run your code on data */
105 OHOS::AafwkBrowserClientAdapterFuzzTest(data, size);
106 return 0;
107 }
108