• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ecmascript/base/string_helper.h"
17 #include "ecmascript/napi/include/jsnapi.h"
18 #include "objectrefall_fuzzer.h"
19 
20 using namespace panda;
21 using namespace panda::ecmascript;
22 
23 namespace OHOS {
ObjectGetPrototypeFuzzTest(const uint8_t * data,size_t size)24     void ObjectGetPrototypeFuzzTest(const uint8_t* data, size_t size)
25     {
26         RuntimeOption option;
27         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
28         EcmaVM *vm = JSNApi::CreateJSVM(option);
29         if (data == nullptr || size <= 0) {
30             LOG_ECMA(ERROR) << "illegal input!";
31             return;
32         }
33         uint8_t *ptr = nullptr;
34         size_t temp = 0;
35         ptr = const_cast<uint8_t*>(data);
36         temp = size;
37         Local<FunctionRef> object = ObjectRef::New(vm);
38         object->GetPrototype(vm);
39         JSNApi::DestroyJSVM(vm);
40     }
41 
ObjectSealFuzzTest(const uint8_t * data,size_t size)42     void ObjectSealFuzzTest(const uint8_t* data, size_t size)
43     {
44         RuntimeOption option;
45         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
46         EcmaVM *vm = JSNApi::CreateJSVM(option);
47         if (data == nullptr || size <= 0) {
48             LOG_ECMA(ERROR) << "illegal input!";
49             return;
50         }
51         uint8_t *ptr = nullptr;
52         size_t temp = 0;
53         ptr = const_cast<uint8_t*>(data);
54         temp = size;
55         Local<ObjectRef> object = ObjectRef::New(vm);
56         object->Seal(vm);
57         JSNApi::DestroyJSVM(vm);
58     }
59 
ObjectFreezeFuzzTest(const uint8_t * data,size_t size)60     void ObjectFreezeFuzzTest(const uint8_t* data, size_t size)
61     {
62         RuntimeOption option;
63         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
64         EcmaVM *vm = JSNApi::CreateJSVM(option);
65         if (data == nullptr || size <= 0) {
66             LOG_ECMA(ERROR) << "illegal input!";
67             return;
68         }
69         uint8_t *ptr = nullptr;
70         size_t temp = 0;
71         ptr = const_cast<uint8_t*>(data);
72         temp = size;
73         Local<ObjectRef> object = ObjectRef::New(vm);
74         object->Freeze(vm);
75         JSNApi::DestroyJSVM(vm);
76     }
77 }
78 
79 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)80 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
81 {
82     // Run your code on data.
83     OHOS::ObjectGetPrototypeFuzzTest(data, size);
84     OHOS::ObjectSealFuzzTest(data, size);
85     OHOS::ObjectFreezeFuzzTest(data, size);
86     return 0;
87 }