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