10826e83eSopenharmony_ci/*
20826e83eSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
30826e83eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40826e83eSopenharmony_ci * you may not use this file except in compliance with the License.
50826e83eSopenharmony_ci * You may obtain a copy of the License at
60826e83eSopenharmony_ci *
70826e83eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80826e83eSopenharmony_ci *
90826e83eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100826e83eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110826e83eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120826e83eSopenharmony_ci * See the License for the specific language governing permissions and
130826e83eSopenharmony_ci * limitations under the License.
140826e83eSopenharmony_ci */
150826e83eSopenharmony_ci
160826e83eSopenharmony_ci#include "ontouchrelease_fuzzer.h"
170826e83eSopenharmony_ci
180826e83eSopenharmony_ci#include <securec.h>
190826e83eSopenharmony_ci
200826e83eSopenharmony_ci#include "nweb.h"
210826e83eSopenharmony_ci#include "nweb_create_window.h"
220826e83eSopenharmony_ci
230826e83eSopenharmony_cinamespace OHOS {
240826e83eSopenharmony_ci    std::shared_ptr<OHOS::NWeb::NWeb> g_nweb = nullptr;
250826e83eSopenharmony_ci    bool OnTouchReleaseFuzzTest(const uint8_t* data, size_t size)
260826e83eSopenharmony_ci    {
270826e83eSopenharmony_ci        if ((data == nullptr) || (size < sizeof(double))) {
280826e83eSopenharmony_ci            return true;
290826e83eSopenharmony_ci        }
300826e83eSopenharmony_ci        g_nweb = NWeb::GetNwebForTest();
310826e83eSopenharmony_ci        if (g_nweb == nullptr) {
320826e83eSopenharmony_ci            return true;
330826e83eSopenharmony_ci        }
340826e83eSopenharmony_ci        uint32_t id;
350826e83eSopenharmony_ci        double x;
360826e83eSopenharmony_ci        double y;
370826e83eSopenharmony_ci        if (memcpy_s(&id, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) {
380826e83eSopenharmony_ci            return true;
390826e83eSopenharmony_ci        }
400826e83eSopenharmony_ci        if (memcpy_s(&x, sizeof(double), data, sizeof(double)) != 0) {
410826e83eSopenharmony_ci            return true;
420826e83eSopenharmony_ci        }
430826e83eSopenharmony_ci        if (memcpy_s(&y, sizeof(double), data, sizeof(double)) != 0) {
440826e83eSopenharmony_ci            return true;
450826e83eSopenharmony_ci        }
460826e83eSopenharmony_ci        g_nweb->OnTouchRelease(id, x, y);
470826e83eSopenharmony_ci        return true;
480826e83eSopenharmony_ci    }
490826e83eSopenharmony_ci}
500826e83eSopenharmony_ci
510826e83eSopenharmony_ci/* Fuzzer entry point */
520826e83eSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
530826e83eSopenharmony_ci{
540826e83eSopenharmony_ci    /* Run your code on data */
550826e83eSopenharmony_ci    OHOS::OnTouchReleaseFuzzTest(data, size);
560826e83eSopenharmony_ci    return 0;
570826e83eSopenharmony_ci}
58