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 "aafwkbrowserhost_fuzzer.h"
17
18 #include <cstring>
19 #include <securec.h>
20
21 #define private public
22 #include "aafwk_app_mgr_client_adapter_impl.h"
23 #include "aafwk_browser_host_impl.h"
24 #include "aafwk_render_scheduler_impl.h"
25 #undef private
26
27 #include "aafwk_render_scheduler_host_adapter.h"
28 #include "app_mgr_client.h"
29 #include "ohos_adapter_helper.h"
30
31 using namespace OHOS::NWeb;
32
33 namespace OHOS {
AafwkBrowserHostFuzzTest(const uint8_t * data,size_t size)34 bool AafwkBrowserHostFuzzTest(const uint8_t* data, size_t size)
35 {
36 std::shared_ptr<AafwkBrowserHostAdapter> hostAdapter = nullptr;
37 auto host = new AafwkBrowserHostImpl(hostAdapter);
38 uint32_t code = 0;
39 int32_t surface_id = 0;
40 MessageParcel newdata;
41 MessageParcel reply;
42 MessageOption option;
43 host->OnRemoteRequest(code, newdata, reply, option);
44 code = 0;
45 host->OnRemoteRequest(code, newdata, reply, option);
46 host->HandleQueryRenderSurface(newdata, reply);
47 host->HandleReportThread(newdata, reply);
48 host->HandlePassSurface(newdata, reply);
49 host->HandleDestroyRenderSurface(newdata, reply);
50 sptr<Surface> surface;
51 host->PassSurface(surface, surface_id);
52 return true;
53 }
54 } // namespace OHOS
55
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59 /* Run your code on data */
60 OHOS::AafwkBrowserHostFuzzTest(data, size);
61 return 0;
62 }
63