• 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 <fuzzer/FuzzedDataProvider.h>
17 #include "ecmascript/global_env.h"
18 #include "ecmascript/napi/include/jsnapi.h"
19 #include "propertyattribute_fuzzer.h"
20 
21 using namespace panda;
22 using namespace panda::ecmascript;
23 
24 namespace OHOS {
PropertyAttributeFuzzTest(const uint8_t * data,size_t size)25 void PropertyAttributeFuzzTest(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     if (data == nullptr || size <= 0) {
34         LOG_ECMA(ERROR) << "illegal input!";
35         return;
36     }
37     uint8_t *ptr = nullptr;
38     ptr = const_cast<uint8_t *>(data);
39     PropertyAttribute::Default();
40     JSNApi::DestroyJSVM(vm);
41 }
42 
PropertyAttributeSetIsFuzzTest(const uint8_t * data,size_t size)43 void PropertyAttributeSetIsFuzzTest(const uint8_t *data, size_t size)
44 {
45     RuntimeOption option;
46     option.SetLogLevel(common::LOG_LEVEL::ERROR);
47     EcmaVM *vm = JSNApi::CreateJSVM(option);
48     if (data == nullptr || size <= 0) {
49         LOG_ECMA(ERROR) << "illegal input!";
50         return;
51     }
52 
53     FuzzedDataProvider fdp(data, size);
54     bool w = fdp.ConsumeBool();
55     bool e = fdp.ConsumeBool();
56     bool c = fdp.ConsumeBool();
57 
58     Local<JSValueRef> jsvalueref;
59     PropertyAttribute propertyattribute(jsvalueref, w, e, c);
60     propertyattribute.SetWritable(e);
61     propertyattribute.IsWritable();
62     propertyattribute.SetEnumerable(e);
63     propertyattribute.IsEnumerable();
64     propertyattribute.SetConfigurable(e);
65     propertyattribute.IsConfigurable();
66     propertyattribute.HasWritable();
67     propertyattribute.HasEnumerable();
68     propertyattribute.HasConfigurable();
69     propertyattribute.SetValue(jsvalueref);
70     propertyattribute.GetValue(vm);
71     propertyattribute.HasValue();
72     propertyattribute.SetSetter(jsvalueref);
73     propertyattribute.GetSetter(vm);
74     propertyattribute.HasSetter();
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::PropertyAttributeFuzzTest(data, size);
84     OHOS::PropertyAttributeSetIsFuzzTest(data, size);
85     return 0;
86 }