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 <fuzzer/FuzzedDataProvider.h>
17 #include "ecmascript/base/string_helper.h"
18 #include "ecmascript/napi/include/jsnapi.h"
19 #include "objectrefall_fuzzer.h"
20
21 using namespace panda;
22 using namespace panda::ecmascript;
23
24 namespace OHOS {
ObjectGetPrototypeFuzzTest(const uint8_t * data,size_t size)25 void ObjectGetPrototypeFuzzTest(const uint8_t* data, size_t size)
26 {
27 FuzzedDataProvider fdp(data, size);
28 const int arkProp = fdp.ConsumeIntegral<int>();
29 RuntimeOption option;
30 option.SetLogLevel(common::LOG_LEVEL::ERROR);
31 option.SetArkProperties(arkProp);
32 EcmaVM *vm = JSNApi::CreateJSVM(option);
33 Local<FunctionRef> object = ObjectRef::New(vm);
34 object->GetPrototype(vm);
35 JSNApi::DestroyJSVM(vm);
36 }
37
ObjectSealFuzzTest(const uint8_t * data,size_t size)38 void ObjectSealFuzzTest(const uint8_t* data, size_t size)
39 {
40 FuzzedDataProvider fdp(data, size);
41 const int arkProp = fdp.ConsumeIntegral<int>();
42 RuntimeOption option;
43 option.SetLogLevel(common::LOG_LEVEL::ERROR);
44 option.SetArkProperties(arkProp);
45 EcmaVM *vm = JSNApi::CreateJSVM(option);
46 Local<ObjectRef> object = ObjectRef::New(vm);
47 object->Seal(vm);
48 JSNApi::DestroyJSVM(vm);
49 }
50
ObjectFreezeFuzzTest(const uint8_t * data,size_t size)51 void ObjectFreezeFuzzTest(const uint8_t* data, size_t size)
52 {
53 FuzzedDataProvider fdp(data, size);
54 const int arkProp = fdp.ConsumeIntegral<int>();
55 RuntimeOption option;
56 option.SetLogLevel(common::LOG_LEVEL::ERROR);
57 option.SetArkProperties(arkProp);
58 EcmaVM *vm = JSNApi::CreateJSVM(option);
59 Local<ObjectRef> object = ObjectRef::New(vm);
60 object->Freeze(vm);
61 JSNApi::DestroyJSVM(vm);
62 }
63 }
64
65 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)66 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
67 {
68 // Run your code on data.
69 OHOS::ObjectGetPrototypeFuzzTest(data, size);
70 OHOS::ObjectSealFuzzTest(data, size);
71 OHOS::ObjectFreezeFuzzTest(data, size);
72 return 0;
73 }