diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 123ea5385d..7684d2c24d 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -19,6 +19,7 @@ group("fuzztest") { "arraybufferrefnew_fuzzer:fuzztest", "arraybufferrefnewwithtwoparameters_fuzzer:fuzztest", "arraylist_fuzzer:fuzztest", + "arrayref_fuzzer:fuzztest", "bigint64arrayrefnew_fuzzer:fuzztest", "bigintrefgetwordsarraysize_fuzzer:fuzztest", "bigintrefnew_fuzzer:fuzztest", @@ -199,14 +200,17 @@ group("fuzztest") { "createbigwords_fuzzer:fuzztest", "dataviewrefnew_fuzzer:fuzztest", "daterefnew_fuzzer:fuzztest", + "deleteworker_fuzzer:fuzztest", "dumpheapsnapshot1_fuzzer:fuzztest", "dumpheapsnapshot2_fuzzer:fuzztest", "dumpheapsnapshot3_fuzzer:fuzztest", "exceptionaggregateerror_fuzzer:fuzztest", + "exceptionclass_fuzzer:fuzztest", "exceptionevalerror_fuzzer:fuzztest", "exceptionoomerror_fuzzer:fuzztest", "exceptiontypeerror_fuzzer:fuzztest", "execute_fuzzer:fuzztest", + "executionscope_fuzzer:fuzztest", "float32arrayrefnew_fuzzer:fuzztest", "float64arrayrefnew_fuzzer:fuzztest", "functionrefcall_fuzzer:fuzztest", @@ -214,12 +218,16 @@ group("fuzztest") { "functionrefnew_fuzzer:fuzztest", "functionrefnewclassfunction_fuzzer:fuzztest", "getallocationprofile_fuzzer:fuzztest", + "getassetpath_fuzzer:fuzztest", + "getbundlename_fuzzer:fuzztest", + "getmodulename_fuzzer:fuzztest", "getnativepointerfield_fuzzer:fuzztest", "getwordsarray_fuzzer:fuzztest", "int16arrayrefnew_fuzzer:fuzztest", "int32arrayrefnew_fuzzer:fuzztest", "int8arrayrefnew_fuzzer:fuzztest", "integerrefnewvalue_fuzzer:fuzztest", + "isquickfixcausedexception_fuzzer:fuzztest", "jsnapideleteserializationdata_fuzzer:fuzztest", "jsnapideserializevalue_fuzzer:fuzztest", "jsnapiexception_fuzzer:fuzztest", @@ -238,6 +246,7 @@ group("fuzztest") { "jsnapistartdebugger_fuzzer:fuzztest", "jsnapiuncaughtclearexception_fuzzer:fuzztest", "jsnapiuncaughtexception_fuzzer:fuzztest", + "jsnapiunloadpatch_fuzzer:fuzztest", "jsnapivalue_fuzzer:fuzztest", "jsonparse_fuzzer:fuzztest", "jsonstringify_fuzzer:fuzztest", @@ -263,11 +272,14 @@ group("fuzztest") { "jsvaluerefispromisevalue_fuzzer:fuzztest", "jsvaluerefissharedarraybuffer_fuzzer:fuzztest", "jsvaluerefnullvalue_fuzzer:fuzztest", + "jsvaluerefobject_fuzzer:fuzztest", "jsvaluereftobigint_fuzzer:fuzztest", "jsvaluereftobooleanvalue_fuzzer:fuzztest", "jsvaluereftonumbervalue_fuzzer:fuzztest", "jsvaluereftoobjectvalue_fuzzer:fuzztest", "jsvaluerefuint32value_fuzzer:fuzztest", + "loadpatch_fuzzer:fuzztest", + "loadpatchlong_fuzzer:fuzztest", "mapiteratorefget_fuzzer:fuzztest", "maprefgetsetkeyvaluesize_fuzzer:fuzztest", "nativepointernew1_fuzzer:fuzztest", @@ -284,6 +296,7 @@ group("fuzztest") { "objectdelete_fuzzer:fuzztest", "objectget_fuzzer:fuzztest", "objecthas_fuzzer:fuzztest", + "objectref_fuzzer:fuzztest", "objectrefall_fuzzer:fuzztest", "objectrefdelete_fuzzer:fuzztest", "objectrefgetglobalobject_fuzzer:fuzztest", @@ -291,12 +304,17 @@ group("fuzztest") { "objectrefsetprototype_fuzzer:fuzztest", "objectset_fuzzer:fuzztest", "primitiverefgetvalue_fuzzer:fuzztest", + "promisecapabilityref_fuzzer:fuzztest", "promiseref_fuzzer:fuzztest", + "promiserejectinfo_fuzzer:fuzztest", "propertyattribute_fuzzer:fuzztest", "publicapilocal_fuzzer:fuzztest", "publicapilocalregexpref_fuzzer:fuzztest", + "registerquickfixqueryfunc_fuzzer:fuzztest", + "setbundlename_fuzzer:fuzztest", "setcpusamplinginterval_fuzzer:fuzztest", "setiteratorrefget_fuzzer:fuzztest", + "setmodulename_fuzzer:fuzztest", "setnativepointerfield_fuzzer:fuzztest", "setnativepointerfieldcount_fuzzer:fuzztest", "snapshotserializebuiltins_fuzzer:fuzztest", @@ -308,8 +326,17 @@ group("fuzztest") { "stopsampling_fuzzer:fuzztest", "stringrefcast_fuzzer:fuzztest", "stringrefgetnapiwrapperstring_fuzzer:fuzztest", + "stringreflength_fuzzer:fuzztest", + "stringrefnewfromutf16_fuzzer:fuzztest", "stringrefnewfromutf8_fuzzer:fuzztest", + "stringrefutf8length_fuzzer:fuzztest", + "stringrefwritelatin1_fuzzer:fuzztest", + "stringrefwriteutf16_fuzzer:fuzztest", "symbolnew_fuzzer:fuzztest", + "templateclassglobal_fuzzer:fuzztest", + "tonativepointer_fuzzer:fuzztest", + "trycatch_fuzzer:fuzztest", + "typedarrayref_fuzzer:fuzztest", "uint16arrayrefnew_fuzzer:fuzztest", "uint32arrayrefnew_fuzzer:fuzztest", "uint8arrayrefnew_fuzzer:fuzztest", diff --git a/test/fuzztest/arrayref_fuzzer/BUILD.gn b/test/fuzztest/arrayref_fuzzer/BUILD.gn new file mode 100644 index 0000000000..a9518cbe44 --- /dev/null +++ b/test/fuzztest/arrayref_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("ArrayRefFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/arrayref_fuzzer" + + sources = [ "arrayref_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ArrayRefFuzzerTest" ] +} diff --git a/test/fuzztest/arrayref_fuzzer/arrayref_fuzzer.cpp b/test/fuzztest/arrayref_fuzzer/arrayref_fuzzer.cpp new file mode 100644 index 0000000000..3695c01142 --- /dev/null +++ b/test/fuzztest/arrayref_fuzzer/arrayref_fuzzer.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "arrayref_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void ArrayRefNewFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + ArrayRef::New(vm, (uint32_t)size); + JSNApi::DestroyJSVM(vm); + } + + void ArrayRefGetValueAtFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + Local globalObject = JSNApi::GetGlobalObject(vm); + Local property = ArrayRef::New(vm, (uint32_t)size); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + [[maybe_unused]]Local value = property->GetValueAt(vm, globalObject, (uint32_t)size); + JSNApi::DestroyJSVM(vm); + } + + void ArrayRefLengthFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local property = ArrayRef::New(vm, (uint32_t)size); + property->Length(vm); + JSNApi::DestroyJSVM(vm); + } + + void ArrayRefSetValueAtFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local globalObject = JSNApi::GetGlobalObject(vm); + Local property = ArrayRef::New(vm, (uint32_t)size); + Local value = ObjectRef::New(vm); + [[maybe_unused]]bool result = property->SetValueAt(vm, globalObject, (uint32_t)size, value); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::ArrayRefNewFuzzerTest(data, size); + OHOS::ArrayRefGetValueAtFuzzerTest(data, size); + OHOS::ArrayRefLengthFuzzerTest(data, size); + OHOS::ArrayRefSetValueAtFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/arrayref_fuzzer/arrayref_fuzzer.h b/test/fuzztest/arrayref_fuzzer/arrayref_fuzzer.h new file mode 100644 index 0000000000..82e97b79a5 --- /dev/null +++ b/test/fuzztest/arrayref_fuzzer/arrayref_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARRAYREF_FUZZER_H +#define ARRAYREF_FUZZER_H + +#define FUZZ_PROJECT_NAME "arrayref_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/arrayref_fuzzer/corpus/init b/test/fuzztest/arrayref_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/arrayref_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/arrayref_fuzzer/project.xml b/test/fuzztest/arrayref_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/arrayref_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/deleteworker_fuzzer/BUILD.gn b/test/fuzztest/deleteworker_fuzzer/BUILD.gn new file mode 100644 index 0000000000..e342334793 --- /dev/null +++ b/test/fuzztest/deleteworker_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("DeleteWorkerFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/deleteworker_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "deleteworker_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":DeleteWorkerFuzzTest" ] +} diff --git a/test/fuzztest/deleteworker_fuzzer/corpus/init b/test/fuzztest/deleteworker_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/deleteworker_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/deleteworker_fuzzer/deleteworker_fuzzer.cpp b/test/fuzztest/deleteworker_fuzzer/deleteworker_fuzzer.cpp new file mode 100644 index 0000000000..1b05f28dad --- /dev/null +++ b/test/fuzztest/deleteworker_fuzzer/deleteworker_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "deleteworker_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void DeleteWorkerFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::DeleteWorker(vm, nullptr); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DeleteWorkerFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/deleteworker_fuzzer/deleteworker_fuzzer.h b/test/fuzztest/deleteworker_fuzzer/deleteworker_fuzzer.h new file mode 100644 index 0000000000..b01cce8112 --- /dev/null +++ b/test/fuzztest/deleteworker_fuzzer/deleteworker_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DELETEWORKER_FUZZER_H +#define DELETEWORKER_FUZZER_H + +#define FUZZ_PROJECT_NAME "deleteworker_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/deleteworker_fuzzer/project.xml b/test/fuzztest/deleteworker_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/deleteworker_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/exceptionclass_fuzzer/BUILD.gn b/test/fuzztest/exceptionclass_fuzzer/BUILD.gn new file mode 100644 index 0000000000..ca648ad5bb --- /dev/null +++ b/test/fuzztest/exceptionclass_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("ExpectionClassFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/exceptionclass_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "exceptionclass_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ExpectionClassFuzzTest" ] +} diff --git a/test/fuzztest/exceptionclass_fuzzer/corpus/init b/test/fuzztest/exceptionclass_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/exceptionclass_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/exceptionclass_fuzzer/exceptionclass_fuzzer.cpp b/test/fuzztest/exceptionclass_fuzzer/exceptionclass_fuzzer.cpp new file mode 100644 index 0000000000..8fcbc19b91 --- /dev/null +++ b/test/fuzztest/exceptionclass_fuzzer/exceptionclass_fuzzer.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "exceptionclass_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void ExpectionErrorFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local message = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + [[maybe_unused]]Local error = Exception::Error(vm, message); + JSNApi::DestroyJSVM(vm); + } + + void ExpectionRangeErrorFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local message = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + [[maybe_unused]]Local error = Exception::RangeError(vm, message); + JSNApi::DestroyJSVM(vm); + } + + void ReferenceErrorFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local message = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + [[maybe_unused]]Local error = Exception::ReferenceError(vm, message); + JSNApi::DestroyJSVM(vm); + } + + void SYNTexErrorFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local message = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + [[maybe_unused]]Local error = Exception::SyntaxError(vm, message); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::ExpectionErrorFuzzTest(data, size); + OHOS::ExpectionRangeErrorFuzzTest(data, size); + OHOS::ReferenceErrorFuzzTest(data, size); + OHOS::SYNTexErrorFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/exceptionclass_fuzzer/exceptionclass_fuzzer.h b/test/fuzztest/exceptionclass_fuzzer/exceptionclass_fuzzer.h new file mode 100644 index 0000000000..9a98f7084a --- /dev/null +++ b/test/fuzztest/exceptionclass_fuzzer/exceptionclass_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EXCEPTIONCLASS_FUZZER_H +#define EXCEPTIONCLASS_FUZZER_H + +#define FUZZ_PROJECT_NAME "exceptionclass_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/exceptionclass_fuzzer/project.xml b/test/fuzztest/exceptionclass_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/exceptionclass_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/executionscope_fuzzer/BUILD.gn b/test/fuzztest/executionscope_fuzzer/BUILD.gn new file mode 100644 index 0000000000..1c95cefcc2 --- /dev/null +++ b/test/fuzztest/executionscope_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +############################hydra-fuzz############################## +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +############################fuzztest################################ +ohos_fuzztest("ExecutionScopeFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/executionscope_fuzzer" + + sources = [ "executionscope_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ExecutionScopeFuzzTest" ] +} diff --git a/test/fuzztest/executionscope_fuzzer/corpus/init b/test/fuzztest/executionscope_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/executionscope_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/executionscope_fuzzer/executionscope_fuzzer.cpp b/test/fuzztest/executionscope_fuzzer/executionscope_fuzzer.cpp new file mode 100644 index 0000000000..c51372b921 --- /dev/null +++ b/test/fuzztest/executionscope_fuzzer/executionscope_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "executionscope_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +namespace OHOS { + void ExecutionScopeFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSExecutionScope jsexecutionScope(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::ExecutionScopeFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/executionscope_fuzzer/executionscope_fuzzer.h b/test/fuzztest/executionscope_fuzzer/executionscope_fuzzer.h new file mode 100644 index 0000000000..8b8e74c49f --- /dev/null +++ b/test/fuzztest/executionscope_fuzzer/executionscope_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EXECUTIONSCOPE_FUZZER_H +#define EXECUTIONSCOPE_FUZZER_H + +#define FUZZ_PROJECT_NAME "executionscope_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/executionscope_fuzzer/project.xml b/test/fuzztest/executionscope_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/executionscope_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getassetpath_fuzzer/BUILD.gn b/test/fuzztest/getassetpath_fuzzer/BUILD.gn new file mode 100644 index 0000000000..79ca5b5367 --- /dev/null +++ b/test/fuzztest/getassetpath_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("GetAssetPathFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/getassetpath_fuzzer" + + sources = [ "getassetpath_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetAssetPathFuzzerTest" ] +} diff --git a/test/fuzztest/getassetpath_fuzzer/corpus/init b/test/fuzztest/getassetpath_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/getassetpath_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getassetpath_fuzzer/getassetpath_fuzzer.cpp b/test/fuzztest/getassetpath_fuzzer/getassetpath_fuzzer.cpp new file mode 100644 index 0000000000..33fc6fb7b4 --- /dev/null +++ b/test/fuzztest/getassetpath_fuzzer/getassetpath_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "getassetpath_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void GetAssetPathFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::SetAssetPath(vm, (char*)data); + [[maybe_unused]]std::string res = JSNApi::GetAssetPath(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::GetAssetPathFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getassetpath_fuzzer/getassetpath_fuzzer.h b/test/fuzztest/getassetpath_fuzzer/getassetpath_fuzzer.h new file mode 100644 index 0000000000..92de07a8b4 --- /dev/null +++ b/test/fuzztest/getassetpath_fuzzer/getassetpath_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GETASSETPATH_FUZZER_H +#define GETASSETPATH_FUZZER_H + +#define FUZZ_PROJECT_NAME "getassetpath_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/getassetpath_fuzzer/project.xml b/test/fuzztest/getassetpath_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/getassetpath_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getbundlename_fuzzer/BUILD.gn b/test/fuzztest/getbundlename_fuzzer/BUILD.gn new file mode 100644 index 0000000000..9653a55915 --- /dev/null +++ b/test/fuzztest/getbundlename_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("GetBundleNameFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/getbundlename_fuzzer" + + sources = [ "getbundlename_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetBundleNameFuzzerTest" ] +} diff --git a/test/fuzztest/getbundlename_fuzzer/corpus/init b/test/fuzztest/getbundlename_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/getbundlename_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getbundlename_fuzzer/getbundlename_fuzzer.cpp b/test/fuzztest/getbundlename_fuzzer/getbundlename_fuzzer.cpp new file mode 100644 index 0000000000..8987f7b164 --- /dev/null +++ b/test/fuzztest/getbundlename_fuzzer/getbundlename_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "getbundlename_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void GetBundleNameFuzzerTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::SetBundleName(vm, (char*)data); + [[maybe_unused]]std::string res = JSNApi::GetBundleName(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::GetBundleNameFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getbundlename_fuzzer/getbundlename_fuzzer.h b/test/fuzztest/getbundlename_fuzzer/getbundlename_fuzzer.h new file mode 100644 index 0000000000..7d91f2accd --- /dev/null +++ b/test/fuzztest/getbundlename_fuzzer/getbundlename_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GETBUNDLENAME_FUZZER_H +#define GETBUNDLENAME_FUZZER_H + +#define FUZZ_PROJECT_NAME "getbundlename_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/getbundlename_fuzzer/project.xml b/test/fuzztest/getbundlename_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/getbundlename_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getmodulename_fuzzer/BUILD.gn b/test/fuzztest/getmodulename_fuzzer/BUILD.gn new file mode 100644 index 0000000000..b31e038475 --- /dev/null +++ b/test/fuzztest/getmodulename_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("GetModuleNameFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/getmodulename_fuzzer" + + sources = [ "getmodulename_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetModuleNameFuzzerTest" ] +} diff --git a/test/fuzztest/getmodulename_fuzzer/corpus/init b/test/fuzztest/getmodulename_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/getmodulename_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/getmodulename_fuzzer/getmodulename_fuzzer.cpp b/test/fuzztest/getmodulename_fuzzer/getmodulename_fuzzer.cpp new file mode 100644 index 0000000000..c4dbc77110 --- /dev/null +++ b/test/fuzztest/getmodulename_fuzzer/getmodulename_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "getmodulename_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void GetModuleNameFuzzerTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::SetModuleName(vm, (char*)data); + [[maybe_unused]]std::string res = JSNApi::GetModuleName(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::GetModuleNameFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getmodulename_fuzzer/getmodulename_fuzzer.h b/test/fuzztest/getmodulename_fuzzer/getmodulename_fuzzer.h new file mode 100644 index 0000000000..5d1bb53d4a --- /dev/null +++ b/test/fuzztest/getmodulename_fuzzer/getmodulename_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GETMODULENAME_FUZZER_H +#define GETMODULENAME_FUZZER_H + +#define FUZZ_PROJECT_NAME "getmodulename_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/getmodulename_fuzzer/project.xml b/test/fuzztest/getmodulename_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/getmodulename_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/isquickfixcausedexception_fuzzer/BUILD.gn b/test/fuzztest/isquickfixcausedexception_fuzzer/BUILD.gn new file mode 100644 index 0000000000..cf952f8540 --- /dev/null +++ b/test/fuzztest/isquickfixcausedexception_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("IsQuickFixCausedExceptionFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/isquickfixcausedexception_fuzzer" + + sources = [ "isquickfixcausedexception_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":IsQuickFixCausedExceptionFuzzerTest" ] +} diff --git a/test/fuzztest/isquickfixcausedexception_fuzzer/corpus/init b/test/fuzztest/isquickfixcausedexception_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/isquickfixcausedexception_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/isquickfixcausedexception_fuzzer/isquickfixcausedexception_fuzzer.cpp b/test/fuzztest/isquickfixcausedexception_fuzzer/isquickfixcausedexception_fuzzer.cpp new file mode 100644 index 0000000000..55cfad21a2 --- /dev/null +++ b/test/fuzztest/isquickfixcausedexception_fuzzer/isquickfixcausedexception_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "isquickfixcausedexception_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void IsQuickFixCausedExceptionFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + std::string patchFileName = "index.abc"; + Local exception = JSNApi::GetAndClearUncaughtException(vm); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::IsQuickFixCausedException(vm, exception, patchFileName); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::IsQuickFixCausedExceptionFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/isquickfixcausedexception_fuzzer/isquickfixcausedexception_fuzzer.h b/test/fuzztest/isquickfixcausedexception_fuzzer/isquickfixcausedexception_fuzzer.h new file mode 100644 index 0000000000..31205d0465 --- /dev/null +++ b/test/fuzztest/isquickfixcausedexception_fuzzer/isquickfixcausedexception_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ISQUICKFIXCAUSEDEXCEPTION_FUZZER_H +#define ISQUICKFIXCAUSEDEXCEPTION_FUZZER_H + +#define FUZZ_PROJECT_NAME "isquickfixcausedexception_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/isquickfixcausedexception_fuzzer/project.xml b/test/fuzztest/isquickfixcausedexception_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/isquickfixcausedexception_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/jsnapiunloadpatch_fuzzer/BUILD.gn b/test/fuzztest/jsnapiunloadpatch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..2d7ec64e2b --- /dev/null +++ b/test/fuzztest/jsnapiunloadpatch_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("JSNApiUnloadPatchTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/jsnapiunloadpatch_fuzzer" + + sources = [ "jsnapiunloadpatch_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":JSNApiUnloadPatchTest" ] +} diff --git a/test/fuzztest/jsnapiunloadpatch_fuzzer/corpus/init b/test/fuzztest/jsnapiunloadpatch_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/jsnapiunloadpatch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/jsnapiunloadpatch_fuzzer/jsnapiunloadpatch_fuzzer.cpp b/test/fuzztest/jsnapiunloadpatch_fuzzer/jsnapiunloadpatch_fuzzer.cpp new file mode 100644 index 0000000000..4bc50d0296 --- /dev/null +++ b/test/fuzztest/jsnapiunloadpatch_fuzzer/jsnapiunloadpatch_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jsnapiunloadpatch_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void JSNApiUnloadPatchTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + std::string patchFileName = "index.abc"; + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::UnloadPatch(vm, patchFileName); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::JSNApiUnloadPatchTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/jsnapiunloadpatch_fuzzer/jsnapiunloadpatch_fuzzer.h b/test/fuzztest/jsnapiunloadpatch_fuzzer/jsnapiunloadpatch_fuzzer.h new file mode 100644 index 0000000000..2dbb059769 --- /dev/null +++ b/test/fuzztest/jsnapiunloadpatch_fuzzer/jsnapiunloadpatch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JSNAPIUNLOADPATCH_FUZZER_H +#define JSNAPIUNLOADPATCH_FUZZER_H + +#define FUZZ_PROJECT_NAME "jsnapiunloadpatch_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/jsnapiunloadpatch_fuzzer/project.xml b/test/fuzztest/jsnapiunloadpatch_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/jsnapiunloadpatch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/jsvaluerefobject_fuzzer/BUILD.gn b/test/fuzztest/jsvaluerefobject_fuzzer/BUILD.gn new file mode 100644 index 0000000000..3dfb6350ce --- /dev/null +++ b/test/fuzztest/jsvaluerefobject_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("JSValueRefObjectFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/jsvaluerefobject_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "jsvaluerefobject_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":JSValueRefObjectFuzzTest" ] +} diff --git a/test/fuzztest/jsvaluerefobject_fuzzer/corpus/init b/test/fuzztest/jsvaluerefobject_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/jsvaluerefobject_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp b/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp new file mode 100644 index 0000000000..195b9505b5 --- /dev/null +++ b/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.cpp @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "jsvaluerefobject_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "ecmascript/napi/jsnapi_helper.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void JSValueRefIsSymbolFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local description = StringRef::NewFromUtf8(vm, (char*)data, size); + Local symbol = SymbolRef::New(vm, description); + symbol->IsSymbol(); + JSNApi::DestroyJSVM(vm); + } + + void JSValueRefIsBigIntFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + constexpr int input = 2147483646; + Local intValue = IntegerRef::New(vm, input); + [[maybe_unused]]bool res = intValue->IsBigInt(); + JSNApi::DestroyJSVM(vm); + } + + void JSValueRefIsObjectFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local res = IntegerRef::New(vm, (int)size); + [[maybe_unused]]bool result = res->IsObject(); + JSNApi::DestroyJSVM(vm); + } + + void IsArgumentsObjectFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + ObjectFactory *factory = vm->GetFactory(); + JSHandle obj = factory->NewJSArguments(); + JSHandle argumentTag = JSHandle::Cast(obj); + JSNApiHelper::ToLocal(argumentTag)->IsArgumentsObject(); + JSNApi::DestroyJSVM(vm); + } + + void IsJSPrimitiveBooleanFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + int length = 8; + Local obj = StringRef::NewFromUtf16(vm, (char16_t*)data, length); + obj->IsJSPrimitiveBoolean(); + JSNApi::DestroyJSVM(vm); + } + + void IsGeneratorFunctionFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + int length = 8; + Local obj = StringRef::NewFromUtf16(vm, (char16_t*)data, length); + obj->IsGeneratorFunction(); + JSNApi::DestroyJSVM(vm); + } + + void IsMapIteratorFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + JSRuntimeOptions option; + EcmaVM *vm = JSNApi::CreateEcmaVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local object = IntegerRef::New(vm, (int)size); + object->IsMapIterator(); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::JSValueRefIsSymbolFuzzTest(data, size); + OHOS::JSValueRefIsBigIntFuzzTest(data, size); + OHOS::JSValueRefIsObjectFuzzTest(data, size); + OHOS::IsArgumentsObjectFuzzTest(data, size); + OHOS::IsJSPrimitiveBooleanFuzzTest(data, size); + OHOS::IsGeneratorFunctionFuzzTest(data, size); + OHOS::IsMapIteratorFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.h b/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.h new file mode 100644 index 0000000000..506f6366aa --- /dev/null +++ b/test/fuzztest/jsvaluerefobject_fuzzer/jsvaluerefobject_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef JSVALUEREFOBJECT_FUZZER_H +#define JSVALUEREFOBJECT_FUZZER_H + +#define FUZZ_PROJECT_NAME "jsvaluerefobject_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/jsvaluerefobject_fuzzer/project.xml b/test/fuzztest/jsvaluerefobject_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/jsvaluerefobject_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/loadpatch_fuzzer/BUILD.gn b/test/fuzztest/loadpatch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..89bd7c8205 --- /dev/null +++ b/test/fuzztest/loadpatch_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("LoadPatchFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/loadpatch_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "loadpatch_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":LoadPatchFuzzTest" ] +} diff --git a/test/fuzztest/loadpatch_fuzzer/corpus/init b/test/fuzztest/loadpatch_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/loadpatch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/loadpatch_fuzzer/loadpatch_fuzzer.cpp b/test/fuzztest/loadpatch_fuzzer/loadpatch_fuzzer.cpp new file mode 100644 index 0000000000..9e050313f4 --- /dev/null +++ b/test/fuzztest/loadpatch_fuzzer/loadpatch_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "loadpatch_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void LoadPatchFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + std::string baseFileName = "index.abc"; + std::string patchFileName = "index.abc"; + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::LoadPatch(vm, patchFileName, baseFileName); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::LoadPatchFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/loadpatch_fuzzer/loadpatch_fuzzer.h b/test/fuzztest/loadpatch_fuzzer/loadpatch_fuzzer.h new file mode 100644 index 0000000000..6a3cba24ca --- /dev/null +++ b/test/fuzztest/loadpatch_fuzzer/loadpatch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOADPATCH_FUZZER_H +#define LOADPATCH_FUZZER_H + +#define FUZZ_PROJECT_NAME "loadpatch_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/loadpatch_fuzzer/project.xml b/test/fuzztest/loadpatch_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/loadpatch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/loadpatchlong_fuzzer/BUILD.gn b/test/fuzztest/loadpatchlong_fuzzer/BUILD.gn new file mode 100644 index 0000000000..305173c8ec --- /dev/null +++ b/test/fuzztest/loadpatchlong_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("LoadPatchLongFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/loadpatchlong_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "loadpatchlong_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":LoadPatchLongFuzzTest" ] +} diff --git a/test/fuzztest/loadpatchlong_fuzzer/corpus/init b/test/fuzztest/loadpatchlong_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/loadpatchlong_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/loadpatchlong_fuzzer/loadpatchlong_fuzzer.cpp b/test/fuzztest/loadpatchlong_fuzzer/loadpatchlong_fuzzer.cpp new file mode 100644 index 0000000000..86609640de --- /dev/null +++ b/test/fuzztest/loadpatchlong_fuzzer/loadpatchlong_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "loadpatchlong_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void LoadPatchLongFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + std::string baseFileName = "index.abc"; + std::string patchFileName = "index.abc"; + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::LoadPatch(vm, patchFileName, (void *)data, size, baseFileName, (void *)data, size); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::LoadPatchLongFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/loadpatchlong_fuzzer/loadpatchlong_fuzzer.h b/test/fuzztest/loadpatchlong_fuzzer/loadpatchlong_fuzzer.h new file mode 100644 index 0000000000..82272d780e --- /dev/null +++ b/test/fuzztest/loadpatchlong_fuzzer/loadpatchlong_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LOADPATCHLONG_FUZZER_H +#define LOADPATCHLONG_FUZZER_H + +#define FUZZ_PROJECT_NAME "loadpatchlong_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/loadpatchlong_fuzzer/project.xml b/test/fuzztest/loadpatchlong_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/loadpatchlong_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/objectref_fuzzer/BUILD.gn b/test/fuzztest/objectref_fuzzer/BUILD.gn new file mode 100644 index 0000000000..e9e94eaeeb --- /dev/null +++ b/test/fuzztest/objectref_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("ObjectRefFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/objectref_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "objectref_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ObjectRefFuzzTest" ] +} diff --git a/test/fuzztest/objectref_fuzzer/corpus/init b/test/fuzztest/objectref_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/objectref_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/objectref_fuzzer/objectref_fuzzer.cpp b/test/fuzztest/objectref_fuzzer/objectref_fuzzer.cpp new file mode 100644 index 0000000000..a53a21d279 --- /dev/null +++ b/test/fuzztest/objectref_fuzzer/objectref_fuzzer.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "objectref_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using FunctionForRef = Local(*)(JsiRuntimeCallInfo*); +namespace OHOS { + Local FuncRefNewCallbackForTest(JsiRuntimeCallInfo* info) + { + LOG_ECMA(ERROR) << "runing FuncRefNewCallbackForTest"; + EscapeLocalScope scope(info->GetVM()); + return scope.Escape(ArrayRef::New(info->GetVM(), info->GetArgsNumber())); + } + void SetAccessorPropertyFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local key = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + FunctionForRef nativeFunc = FuncRefNewCallbackForTest; + Local getter = FunctionRef::New(vm, nativeFunc); + Local setter = FunctionRef::New(vm, nativeFunc); + Local object = ObjectRef::New(vm); + object->SetAccessorProperty(vm, key, getter, setter); + JSNApi::DestroyJSVM(vm); + } + + void DefinePropertyFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local object = ObjectRef::New(vm); + Local key = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local value = ObjectRef::New(vm); + PropertyAttribute attribute(value, true, true, true); + object->DefineProperty(vm, key, attribute); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::SetAccessorPropertyFuzzTest(data, size); + OHOS::DefinePropertyFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/objectref_fuzzer/objectref_fuzzer.h b/test/fuzztest/objectref_fuzzer/objectref_fuzzer.h new file mode 100644 index 0000000000..0f879768bf --- /dev/null +++ b/test/fuzztest/objectref_fuzzer/objectref_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OBJECTREF_FUZZER_H +#define OBJECTREF_FUZZER_H + +#define FUZZ_PROJECT_NAME "objectref_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/objectref_fuzzer/project.xml b/test/fuzztest/objectref_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/objectref_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/promisecapabilityref_fuzzer/BUILD.gn b/test/fuzztest/promisecapabilityref_fuzzer/BUILD.gn new file mode 100644 index 0000000000..65161ed0b8 --- /dev/null +++ b/test/fuzztest/promisecapabilityref_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("PromiseCapabilityRefFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/promisecapabilityref_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "promisecapabilityref_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":PromiseCapabilityRefFuzzTest" ] +} diff --git a/test/fuzztest/promisecapabilityref_fuzzer/corpus/init b/test/fuzztest/promisecapabilityref_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/promisecapabilityref_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/promisecapabilityref_fuzzer/project.xml b/test/fuzztest/promisecapabilityref_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/promisecapabilityref_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/promisecapabilityref_fuzzer/promisecapabilityref_fuzzer.cpp b/test/fuzztest/promisecapabilityref_fuzzer/promisecapabilityref_fuzzer.cpp new file mode 100644 index 0000000000..d6217b9c19 --- /dev/null +++ b/test/fuzztest/promisecapabilityref_fuzzer/promisecapabilityref_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "promisecapabilityref_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void PromiseCapabilityRefNewFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + [[maybe_unused]]Local capability = PromiseCapabilityRef::New(vm); + JSNApi::DestroyJSVM(vm); + } + + void PromiseCapabilityRefResolveFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local capability = PromiseCapabilityRef::New(vm); + Local value = NumberRef::New(vm, (double)size); + capability->Resolve(vm, value); + JSNApi::DestroyJSVM(vm); + } + + void PromiseCapabilityRefRejectFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local capability = PromiseCapabilityRef::New(vm); + Local value = NumberRef::New(vm, (double)size); + capability->Resolve(vm, value); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::PromiseCapabilityRefNewFuzzTest(data, size); + OHOS::PromiseCapabilityRefResolveFuzzTest(data, size); + OHOS::PromiseCapabilityRefRejectFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/promisecapabilityref_fuzzer/promisecapabilityref_fuzzer.h b/test/fuzztest/promisecapabilityref_fuzzer/promisecapabilityref_fuzzer.h new file mode 100644 index 0000000000..c36dc3524b --- /dev/null +++ b/test/fuzztest/promisecapabilityref_fuzzer/promisecapabilityref_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PROMISECAPABILITYREF_FUZZER_H +#define PROMISECAPABILITYREF_FUZZER_H + +#define FUZZ_PROJECT_NAME "promisecapabilityref_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/promiserejectinfo_fuzzer/BUILD.gn b/test/fuzztest/promiserejectinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..aa653589b2 --- /dev/null +++ b/test/fuzztest/promiserejectinfo_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("PromiseRejectInfoFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/promiserejectinfo_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "promiserejectinfo_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":PromiseRejectInfoFuzzTest" ] +} diff --git a/test/fuzztest/promiserejectinfo_fuzzer/corpus/init b/test/fuzztest/promiserejectinfo_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/promiserejectinfo_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/promiserejectinfo_fuzzer/project.xml b/test/fuzztest/promiserejectinfo_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/promiserejectinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/promiserejectinfo_fuzzer/promiserejectinfo_fuzzer.cpp b/test/fuzztest/promiserejectinfo_fuzzer/promiserejectinfo_fuzzer.cpp new file mode 100644 index 0000000000..9de846a11e --- /dev/null +++ b/test/fuzztest/promiserejectinfo_fuzzer/promiserejectinfo_fuzzer.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "promiserejectinfo_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void PromiseRejectInfoNewFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local promiseStirng = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local promise(promiseStirng); + Local reasonString = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local reason(reasonString); + void *data2 = static_cast(new std::string("test")); + [[maybe_unused]]PromiseRejectInfo promiseReject(promise, reason, + PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data2); + JSNApi::DestroyJSVM(vm); + } + + void GetPromiseFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local capability = PromiseCapabilityRef::New(vm); + [[maybe_unused]]Local promise = capability->GetPromise(vm); + JSNApi::DestroyJSVM(vm); + } + + void GetDataFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local promiseStirng = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local promise(promiseStirng); + Local reasonString = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local reason(reasonString); + PromiseRejectInfo promiseReject(promise, reason, + PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, (void*)data); + promiseReject.GetData(); + JSNApi::DestroyJSVM(vm); + } + + void PromiseRejectInfoGetPromiseFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local promiseStirng = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local promise(promiseStirng); + Local reasonString = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local reason(reasonString); + void *newdata = static_cast(new std::string("test")); + PromiseRejectInfo promiseReject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, newdata); + promiseReject.GetPromise(); + JSNApi::DestroyJSVM(vm); + } + + void PromiseRejectInfoGetReasonFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local promiseStirng = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local promise(promiseStirng); + Local reasonString = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local reason(reasonString); + void *data2 = static_cast(new std::string("test")); + PromiseRejectInfo promiseReject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data2); + [[maybe_unused]]Local reason_res = promiseReject.GetReason(); + JSNApi::DestroyJSVM(vm); + } + + void PromiseRejectInfoGetOperationFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local promiseStirng = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local promise(promiseStirng); + Local reasonString = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local reason(reasonString); + void *data2 = static_cast(new std::string("test")); + PromiseRejectInfo promiseReject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data2); + promiseReject.GetOperation(); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::PromiseRejectInfoNewFuzzTest(data, size); + OHOS::GetPromiseFuzzTest(data, size); + OHOS::GetDataFuzzTest(data, size); + OHOS::PromiseRejectInfoGetPromiseFuzzTest(data, size); + OHOS::PromiseRejectInfoGetReasonFuzzTest(data, size); + OHOS::PromiseRejectInfoGetOperationFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/promiserejectinfo_fuzzer/promiserejectinfo_fuzzer.h b/test/fuzztest/promiserejectinfo_fuzzer/promiserejectinfo_fuzzer.h new file mode 100644 index 0000000000..90b7523f60 --- /dev/null +++ b/test/fuzztest/promiserejectinfo_fuzzer/promiserejectinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PROMISEREJECTINFO_FUZZER_H +#define PROMISEREJECTINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "promiserejectinfo_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/registerquickfixqueryfunc_fuzzer/BUILD.gn b/test/fuzztest/registerquickfixqueryfunc_fuzzer/BUILD.gn new file mode 100644 index 0000000000..998c9b1186 --- /dev/null +++ b/test/fuzztest/registerquickfixqueryfunc_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("RegisterQuickFixQueryFuncFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/registerquickfixqueryfunc_fuzzer" + + sources = [ "registerquickfixqueryfunc_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":RegisterQuickFixQueryFuncFuzzerTest" ] +} diff --git a/test/fuzztest/registerquickfixqueryfunc_fuzzer/corpus/init b/test/fuzztest/registerquickfixqueryfunc_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/registerquickfixqueryfunc_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/registerquickfixqueryfunc_fuzzer/project.xml b/test/fuzztest/registerquickfixqueryfunc_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/registerquickfixqueryfunc_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/registerquickfixqueryfunc_fuzzer/registerquickfixqueryfunc_fuzzer.cpp b/test/fuzztest/registerquickfixqueryfunc_fuzzer/registerquickfixqueryfunc_fuzzer.cpp new file mode 100644 index 0000000000..ffd7afcff2 --- /dev/null +++ b/test/fuzztest/registerquickfixqueryfunc_fuzzer/registerquickfixqueryfunc_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "registerquickfixqueryfunc_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + bool QuickFixQueryFunc(std::string baseFileName, std::string &patchFileName, void **patchBuffer, + size_t &patchBufferSize) + { + if (baseFileName != "multi_file/base/merge.abc") { + return false; + } + patchFileName = "__index.pa"; + const char *data = R"( + .function void foo() {} + )"; + char *bufferData = new char[strlen(data) + 1]; + size_t dataSize = strlen(data) + 1; + strcpy_s(bufferData, dataSize, data); + *patchBuffer = reinterpret_cast(bufferData); + patchBufferSize = strlen(data); + return true; + } + void RegisterQuickFixQueryFuncFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::RegisterQuickFixQueryFunc(vm, QuickFixQueryFunc); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::RegisterQuickFixQueryFuncFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/registerquickfixqueryfunc_fuzzer/registerquickfixqueryfunc_fuzzer.h b/test/fuzztest/registerquickfixqueryfunc_fuzzer/registerquickfixqueryfunc_fuzzer.h new file mode 100644 index 0000000000..3a32ac25a4 --- /dev/null +++ b/test/fuzztest/registerquickfixqueryfunc_fuzzer/registerquickfixqueryfunc_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef REGISTERQUICKFIXQUERYFUNC_FUZZER_H +#define REGISTERQUICKFIXQUERYFUNC_FUZZER_H + +#define FUZZ_PROJECT_NAME "registerquickfixqueryfunc_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/setbundlename_fuzzer/BUILD.gn b/test/fuzztest/setbundlename_fuzzer/BUILD.gn new file mode 100644 index 0000000000..a01d0b6e1e --- /dev/null +++ b/test/fuzztest/setbundlename_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("SetBundleNameFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/setbundlename_fuzzer" + + sources = [ "setbundlename_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetBundleNameFuzzerTest" ] +} diff --git a/test/fuzztest/setbundlename_fuzzer/corpus/init b/test/fuzztest/setbundlename_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/setbundlename_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/setbundlename_fuzzer/project.xml b/test/fuzztest/setbundlename_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/setbundlename_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setbundlename_fuzzer/setbundlename_fuzzer.cpp b/test/fuzztest/setbundlename_fuzzer/setbundlename_fuzzer.cpp new file mode 100644 index 0000000000..f38145053d --- /dev/null +++ b/test/fuzztest/setbundlename_fuzzer/setbundlename_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "setbundlename_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void SetBundleNameFuzzerTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::SetBundleName(vm, (char*)data); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::SetBundleNameFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/setbundlename_fuzzer/setbundlename_fuzzer.h b/test/fuzztest/setbundlename_fuzzer/setbundlename_fuzzer.h new file mode 100644 index 0000000000..0b1edfe141 --- /dev/null +++ b/test/fuzztest/setbundlename_fuzzer/setbundlename_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SETBUNDLENAME_FUZZER_H +#define SETBUNDLENAME_FUZZER_H + +#define FUZZ_PROJECT_NAME "setbundlename_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/setmodulename_fuzzer/BUILD.gn b/test/fuzztest/setmodulename_fuzzer/BUILD.gn new file mode 100644 index 0000000000..9c14329927 --- /dev/null +++ b/test/fuzztest/setmodulename_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("SetModuleNameFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/setmodulename_fuzzer" + + sources = [ "setmodulename_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetModuleNameFuzzerTest" ] +} diff --git a/test/fuzztest/setmodulename_fuzzer/corpus/init b/test/fuzztest/setmodulename_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/setmodulename_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/setmodulename_fuzzer/project.xml b/test/fuzztest/setmodulename_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/setmodulename_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/setmodulename_fuzzer/setmodulename_fuzzer.cpp b/test/fuzztest/setmodulename_fuzzer/setmodulename_fuzzer.cpp new file mode 100644 index 0000000000..6f0c7248b0 --- /dev/null +++ b/test/fuzztest/setmodulename_fuzzer/setmodulename_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "setmodulename_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void SetModuleNameFuzzerTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + JSNApi::SetModuleName(vm, (char*)data); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::SetModuleNameFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/setmodulename_fuzzer/setmodulename_fuzzer.h b/test/fuzztest/setmodulename_fuzzer/setmodulename_fuzzer.h new file mode 100644 index 0000000000..74c845dc2f --- /dev/null +++ b/test/fuzztest/setmodulename_fuzzer/setmodulename_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SETMODULENAME_FUZZER_H +#define SETMODULENAME_FUZZER_H + +#define FUZZ_PROJECT_NAME "setmodulename_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/stringreflength_fuzzer/BUILD.gn b/test/fuzztest/stringreflength_fuzzer/BUILD.gn new file mode 100644 index 0000000000..5b9bcaad40 --- /dev/null +++ b/test/fuzztest/stringreflength_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("StringRefLengthFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/stringreflength_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "stringreflength_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":StringRefLengthFuzzTest" ] +} diff --git a/test/fuzztest/stringreflength_fuzzer/corpus/init b/test/fuzztest/stringreflength_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/stringreflength_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/stringreflength_fuzzer/project.xml b/test/fuzztest/stringreflength_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/stringreflength_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/stringreflength_fuzzer/stringreflength_fuzzer.cpp b/test/fuzztest/stringreflength_fuzzer/stringreflength_fuzzer.cpp new file mode 100644 index 0000000000..ef32a3dde3 --- /dev/null +++ b/test/fuzztest/stringreflength_fuzzer/stringreflength_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stringreflength_fuzzer.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/ecma_string-inl.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void StringRefLengthFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local res = StringRef::StringRef::NewFromUtf8(vm, (char*)data, (int)size); + res->Length(); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::StringRefLengthFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/stringreflength_fuzzer/stringreflength_fuzzer.h b/test/fuzztest/stringreflength_fuzzer/stringreflength_fuzzer.h new file mode 100644 index 0000000000..9217d5cbf0 --- /dev/null +++ b/test/fuzztest/stringreflength_fuzzer/stringreflength_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STRINGREFLENGTH_FUZZER_H +#define STRINGREFLENGTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "stringreflength_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/stringrefnewfromutf16_fuzzer/BUILD.gn b/test/fuzztest/stringrefnewfromutf16_fuzzer/BUILD.gn new file mode 100644 index 0000000000..9acb0b2ba4 --- /dev/null +++ b/test/fuzztest/stringrefnewfromutf16_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("StringRefNewFromUtf16FuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/stringrefnewfromutf16_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "stringrefnewfromutf16_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":StringRefNewFromUtf16FuzzTest" ] +} diff --git a/test/fuzztest/stringrefnewfromutf16_fuzzer/corpus/init b/test/fuzztest/stringrefnewfromutf16_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/stringrefnewfromutf16_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/stringrefnewfromutf16_fuzzer/project.xml b/test/fuzztest/stringrefnewfromutf16_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/stringrefnewfromutf16_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp b/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp new file mode 100644 index 0000000000..8ae5f8628e --- /dev/null +++ b/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stringrefnewfromutf16_fuzzer.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/ecma_string-inl.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void StringRefNewFromUtf16FuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + StringRef::NewFromUtf16(vm, (char16_t*)data); + JSNApi::DestroyJSVM(vm); + return; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::StringRefNewFromUtf16FuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.h b/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.h new file mode 100644 index 0000000000..8f55fb58d4 --- /dev/null +++ b/test/fuzztest/stringrefnewfromutf16_fuzzer/stringrefnewfromutf16_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STRINGREFNEWFROMUTF16_FUZZER_H +#define STRINGREFNEWFROMUTF16_FUZZER_H + +#define FUZZ_PROJECT_NAME "stringrefnewfromutf16_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/stringrefutf8length_fuzzer/BUILD.gn b/test/fuzztest/stringrefutf8length_fuzzer/BUILD.gn new file mode 100644 index 0000000000..33703c64d9 --- /dev/null +++ b/test/fuzztest/stringrefutf8length_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("StringRefUtf8LengthFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/stringrefutf8length_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "stringrefutf8length_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":StringRefUtf8LengthFuzzTest" ] +} diff --git a/test/fuzztest/stringrefutf8length_fuzzer/corpus/init b/test/fuzztest/stringrefutf8length_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/stringrefutf8length_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/stringrefutf8length_fuzzer/project.xml b/test/fuzztest/stringrefutf8length_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/stringrefutf8length_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/stringrefutf8length_fuzzer/stringrefutf8length_fuzzer.cpp b/test/fuzztest/stringrefutf8length_fuzzer/stringrefutf8length_fuzzer.cpp new file mode 100644 index 0000000000..29180354d9 --- /dev/null +++ b/test/fuzztest/stringrefutf8length_fuzzer/stringrefutf8length_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stringrefutf8length_fuzzer.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/ecma_string-inl.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void StringRefUtf8LengthFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local res = StringRef::StringRef::NewFromUtf8(vm, (char*)data, (int)size); + res->Utf8Length(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::StringRefUtf8LengthFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/stringrefutf8length_fuzzer/stringrefutf8length_fuzzer.h b/test/fuzztest/stringrefutf8length_fuzzer/stringrefutf8length_fuzzer.h new file mode 100644 index 0000000000..f4130c2b6a --- /dev/null +++ b/test/fuzztest/stringrefutf8length_fuzzer/stringrefutf8length_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STRINGREFUTF8LENGTH_FUZZER_H +#define STRINGREFUTF8LENGTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "stringrefutf8length_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/stringrefwritelatin1_fuzzer/BUILD.gn b/test/fuzztest/stringrefwritelatin1_fuzzer/BUILD.gn new file mode 100644 index 0000000000..ddf412df28 --- /dev/null +++ b/test/fuzztest/stringrefwritelatin1_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("StringRefWriteLatin1FuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/stringrefwritelatin1_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "stringrefwritelatin1_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":StringRefWriteLatin1FuzzTest" ] +} diff --git a/test/fuzztest/stringrefwritelatin1_fuzzer/corpus/init b/test/fuzztest/stringrefwritelatin1_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/stringrefwritelatin1_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/stringrefwritelatin1_fuzzer/project.xml b/test/fuzztest/stringrefwritelatin1_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/stringrefwritelatin1_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/stringrefwritelatin1_fuzzer/stringrefwritelatin1_fuzzer.cpp b/test/fuzztest/stringrefwritelatin1_fuzzer/stringrefwritelatin1_fuzzer.cpp new file mode 100644 index 0000000000..b7cb98d514 --- /dev/null +++ b/test/fuzztest/stringrefwritelatin1_fuzzer/stringrefwritelatin1_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stringrefwritelatin1_fuzzer.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/ecma_string-inl.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void StringRefWriteLatin1FuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local res = StringRef::StringRef::NewFromUtf8(vm, (char*)data, (int)size); + char *value = new char[size](); + if (memcpy_s(value, size, data, size) != EOK) { + LOG_ECMA(ERROR) << "memcpy_s failed!"; + UNREACHABLE(); + } + res->WriteLatin1(value, (int)size); + delete[] value; + value = nullptr; + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::StringRefWriteLatin1FuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/stringrefwritelatin1_fuzzer/stringrefwritelatin1_fuzzer.h b/test/fuzztest/stringrefwritelatin1_fuzzer/stringrefwritelatin1_fuzzer.h new file mode 100644 index 0000000000..82f2847a21 --- /dev/null +++ b/test/fuzztest/stringrefwritelatin1_fuzzer/stringrefwritelatin1_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STRINGREFWRITELATIN1_FUZZER_H +#define STRINGREFWRITELATIN1_FUZZER_H + +#define FUZZ_PROJECT_NAME "stringrefwritelatin1_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/stringrefwriteutf16_fuzzer/BUILD.gn b/test/fuzztest/stringrefwriteutf16_fuzzer/BUILD.gn new file mode 100644 index 0000000000..3aea9720c1 --- /dev/null +++ b/test/fuzztest/stringrefwriteutf16_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("StringRefWriteUtf16FuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/stringrefwriteutf16_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "stringrefwriteutf16_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":StringRefWriteUtf16FuzzTest" ] +} diff --git a/test/fuzztest/stringrefwriteutf16_fuzzer/corpus/init b/test/fuzztest/stringrefwriteutf16_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/stringrefwriteutf16_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/stringrefwriteutf16_fuzzer/project.xml b/test/fuzztest/stringrefwriteutf16_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/stringrefwriteutf16_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp b/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp new file mode 100644 index 0000000000..e9be6bca22 --- /dev/null +++ b/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stringrefwriteutf16_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/base/utf_helper.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::base::utf_helper; + +namespace OHOS { + void StringRefWriteUtf16FuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local res = StringRef::NewFromUtf16(vm, (char16_t*)data); + res->WriteUtf16((char16_t*)data, (int)size); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::StringRefWriteUtf16FuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.h b/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.h new file mode 100644 index 0000000000..abb6794e08 --- /dev/null +++ b/test/fuzztest/stringrefwriteutf16_fuzzer/stringrefwriteutf16_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STRINGREFWRITEUTF16_FUZZER_H +#define STRINGREFWRITEUTF16_FUZZER_H + +#define FUZZ_PROJECT_NAME "stringrefwriteutf16_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/templateclassglobal_fuzzer/BUILD.gn b/test/fuzztest/templateclassglobal_fuzzer/BUILD.gn new file mode 100644 index 0000000000..69983c0a92 --- /dev/null +++ b/test/fuzztest/templateclassglobal_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("TemplateClassGlobalFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/templateclassglobal_fuzzer" + + sources = [ "templateclassglobal_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":TemplateClassGlobalFuzzerTest" ] +} diff --git a/test/fuzztest/templateclassglobal_fuzzer/corpus/init b/test/fuzztest/templateclassglobal_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/templateclassglobal_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/templateclassglobal_fuzzer/project.xml b/test/fuzztest/templateclassglobal_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/templateclassglobal_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/templateclassglobal_fuzzer/templateclassglobal_fuzzer.cpp b/test/fuzztest/templateclassglobal_fuzzer/templateclassglobal_fuzzer.cpp new file mode 100644 index 0000000000..f1d9a04fa0 --- /dev/null +++ b/test/fuzztest/templateclassglobal_fuzzer/templateclassglobal_fuzzer.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "templateclassglobal_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void TemplateGlobalFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local current = BooleanRef::New(vm, true); + [[maybe_unused]]Global global(vm, current); + JSNApi::DestroyJSVM(vm); + } + + void TemplateToLocalFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + [[maybe_unused]]Local local = global.ToLocal(); + JSNApi::DestroyJSVM(vm); + } + + void TemplateToLocalFromVMFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + [[maybe_unused]]Local local = global.ToLocal(vm); + JSNApi::DestroyJSVM(vm); + } + + void TemplateEmptyFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + global.Empty(); + JSNApi::DestroyJSVM(vm); + } + + void TemplateFreeGlobalHandleAddrFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + global.FreeGlobalHandleAddr(); + JSNApi::DestroyJSVM(vm); + } + + void GlobalOperatorStarFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + [[maybe_unused]]bool b = (*global)->BooleaValue(); + JSNApi::DestroyJSVM(vm); + } + + void GlobalOperatorPointToFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + [[maybe_unused]]bool b = global->BooleaValue(); + JSNApi::DestroyJSVM(vm); + } + + void GlobalIsEmptyFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global; + [[maybe_unused]]bool b = global.IsEmpty(); + JSNApi::DestroyJSVM(vm); + } + + void GlobalSetWeakFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + global.SetWeak(); + bool res = global.IsWeak(); + if (!res) { + LOG_ECMA(ERROR) << "SetWeak failed"; + return; + } + + JSNApi::DestroyJSVM(vm); + } + + void GlobalClearWeakFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + global.ClearWeak(); + JSNApi::DestroyJSVM(vm); + } + + void GlobalIsWeakFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Global global(vm, BooleanRef::New(vm, true)); + global.SetWeak(); + [[maybe_unused]]bool b = global.IsWeak(); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::TemplateGlobalFuzzerTest(data, size); + OHOS::TemplateToLocalFuzzerTest(data, size); + OHOS::TemplateToLocalFromVMFuzzerTest(data, size); + OHOS::TemplateEmptyFuzzerTest(data, size); + OHOS::TemplateFreeGlobalHandleAddrFuzzerTest(data, size); + OHOS::GlobalOperatorStarFuzzerTest(data, size); + OHOS::GlobalOperatorPointToFuzzerTest(data, size); + OHOS::GlobalIsEmptyFuzzerTest(data, size); + OHOS::GlobalSetWeakFuzzerTest(data, size); + OHOS::GlobalClearWeakFuzzerTest(data, size); + OHOS::GlobalIsWeakFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/templateclassglobal_fuzzer/templateclassglobal_fuzzer.h b/test/fuzztest/templateclassglobal_fuzzer/templateclassglobal_fuzzer.h new file mode 100644 index 0000000000..3311e67b06 --- /dev/null +++ b/test/fuzztest/templateclassglobal_fuzzer/templateclassglobal_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEMPLATECLASSGLOBAL_FUZZER_H +#define TEMPLATECLASSGLOBAL_FUZZER_H + +#define FUZZ_PROJECT_NAME "templateclassglobal_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/tonativepointer_fuzzer/BUILD.gn b/test/fuzztest/tonativepointer_fuzzer/BUILD.gn new file mode 100644 index 0000000000..fce2bacc55 --- /dev/null +++ b/test/fuzztest/tonativepointer_fuzzer/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################################hydra-fuzz################################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +##################################fuzztest##################################### +ohos_fuzztest("ToNativePointerFuzzTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/tonativepointer_fuzzer" + + resource_config_file = "$js_root/test/resource/js_runtime/ohos_test.xml" + + sources = [ "tonativepointer_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ToNativePointerFuzzTest" ] +} diff --git a/test/fuzztest/tonativepointer_fuzzer/corpus/init b/test/fuzztest/tonativepointer_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/tonativepointer_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/tonativepointer_fuzzer/project.xml b/test/fuzztest/tonativepointer_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/tonativepointer_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/tonativepointer_fuzzer/tonativepointer_fuzzer.cpp b/test/fuzztest/tonativepointer_fuzzer/tonativepointer_fuzzer.cpp new file mode 100644 index 0000000000..551ec858b6 --- /dev/null +++ b/test/fuzztest/tonativepointer_fuzzer/tonativepointer_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "tonativepointer_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void ToNativePointerFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (data == nullptr || size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + Local toString = StringRef::NewFromUtf8(vm, (char*)data, (int)size); + Local toValue(toString); + toValue->ToNativePointer(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::ToNativePointerFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/tonativepointer_fuzzer/tonativepointer_fuzzer.h b/test/fuzztest/tonativepointer_fuzzer/tonativepointer_fuzzer.h new file mode 100644 index 0000000000..9e746bd7a2 --- /dev/null +++ b/test/fuzztest/tonativepointer_fuzzer/tonativepointer_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TONATIVEPOINTER_FUZZER_H +#define TONATIVEPOINTER_FUZZER_H + +#define FUZZ_PROJECT_NAME "tonativepointer_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/trycatch_fuzzer/BUILD.gn b/test/fuzztest/trycatch_fuzzer/BUILD.gn new file mode 100644 index 0000000000..a4137b5882 --- /dev/null +++ b/test/fuzztest/trycatch_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("TryCatchFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/trycatch_fuzzer" + + sources = [ "trycatch_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":TryCatchFuzzerTest" ] +} diff --git a/test/fuzztest/trycatch_fuzzer/corpus/init b/test/fuzztest/trycatch_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/trycatch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/trycatch_fuzzer/project.xml b/test/fuzztest/trycatch_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/trycatch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/trycatch_fuzzer/trycatch_fuzzer.cpp b/test/fuzztest/trycatch_fuzzer/trycatch_fuzzer.cpp new file mode 100644 index 0000000000..8b442f091c --- /dev/null +++ b/test/fuzztest/trycatch_fuzzer/trycatch_fuzzer.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "trycatch_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void TryCatchNewFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + TryCatch trycatch(vm); + JSNApi::DestroyJSVM(vm); + } + + void TryCatchHasCaughtFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + TryCatch trycatch(vm); + trycatch.HasCaught(); + JSNApi::DestroyJSVM(vm); + } + + void TryCatchRethrowFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + TryCatch trycatch(vm); + trycatch.Rethrow(); + JSNApi::DestroyJSVM(vm); + } + + void GetAndClearExceptionFuzzTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + TryCatch trycatch(vm); + trycatch.GetAndClearException(); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::TryCatchNewFuzzerTest(data, size); + OHOS::TryCatchHasCaughtFuzzerTest(data, size); + OHOS::TryCatchRethrowFuzzerTest(data, size); + OHOS::GetAndClearExceptionFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/trycatch_fuzzer/trycatch_fuzzer.h b/test/fuzztest/trycatch_fuzzer/trycatch_fuzzer.h new file mode 100644 index 0000000000..93dfc09d2a --- /dev/null +++ b/test/fuzztest/trycatch_fuzzer/trycatch_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TRYCATCH_FUZZER_H +#define TRYCATCH_FUZZER_H + +#define FUZZ_PROJECT_NAME "trycatch_fuzzer.h" + +#endif \ No newline at end of file diff --git a/test/fuzztest/typedarrayref_fuzzer/BUILD.gn b/test/fuzztest/typedarrayref_fuzzer/BUILD.gn new file mode 100644 index 0000000000..eadbc57952 --- /dev/null +++ b/test/fuzztest/typedarrayref_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################################hydra-fuzz############################### +import("//arkcompiler/ets_runtime/js_runtime_config.gni") +import("//arkcompiler/ets_runtime/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") + +####################################fuzztest################################## +ohos_fuzztest("TypedArrayrefFuzzerTest") { + module_out_path = ets_runtime_output_path + + fuzz_config_file = "$js_root/test/fuzztest/typedarrayref_fuzzer" + + sources = [ "typedarrayref_fuzzer.cpp" ] + + configs = [ "$js_root:ecma_test_config" ] + + deps = [ + "$js_root:libark_jsruntime", + sdk_libc_secshared_dep, + ] + + # hiviewdfx libraries + external_deps = hiviewdfx_ext_deps + deps += hiviewdfx_deps +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":TypedArrayrefFuzzerTest" ] +} diff --git a/test/fuzztest/typedarrayref_fuzzer/corpus/init b/test/fuzztest/typedarrayref_fuzzer/corpus/init new file mode 100644 index 0000000000..69c5791762 --- /dev/null +++ b/test/fuzztest/typedarrayref_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/typedarrayref_fuzzer/project.xml b/test/fuzztest/typedarrayref_fuzzer/project.xml new file mode 100644 index 0000000000..4fdbc407f2 --- /dev/null +++ b/test/fuzztest/typedarrayref_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/typedarrayref_fuzzer/typedarrayref_fuzzer.cpp b/test/fuzztest/typedarrayref_fuzzer/typedarrayref_fuzzer.cpp new file mode 100644 index 0000000000..44cb5c5415 --- /dev/null +++ b/test/fuzztest/typedarrayref_fuzzer/typedarrayref_fuzzer.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "typedarrayref_fuzzer.h" +#include "ecmascript/base/string_helper.h" +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/napi/include/jsnapi.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace OHOS { + void TypedArrayrefArrayLengthFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + constexpr int byteOffset = 5; + constexpr int length = 6; + Local arrayBuffer = ArrayBufferRef::New(vm, (int32_t)size); + Local typedArray = Int8ArrayRef::New(vm, arrayBuffer, byteOffset, length); + typedArray->ArrayLength(vm); + JSNApi::DestroyJSVM(vm); + } + + void TypedArrayrefByteOffSetFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + constexpr int byteOffset = 5; + constexpr int length = 6; + Local arrayBuffer = ArrayBufferRef::New(vm, (int32_t)size); + Local typedArray = Int8ArrayRef::New(vm, arrayBuffer, byteOffset, length); + typedArray->ByteOffset(vm); + JSNApi::DestroyJSVM(vm); + } + + void TypedArrayrefGetArrayBufferFuzzerTest([[maybe_unused]]const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + EcmaVM *vm = JSNApi::CreateJSVM(option); + if (size <= 0) { + LOG_ECMA(ERROR) << "illegal input!"; + return; + } + constexpr int byteOffset = 5; + constexpr int length = 6; + Local arrayBuffer = ArrayBufferRef::New(vm, (int32_t)size); + Local typedArray = Int8ArrayRef::New(vm, arrayBuffer, byteOffset, length); + typedArray->GetArrayBuffer(vm); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::TypedArrayrefArrayLengthFuzzerTest(data, size); + OHOS::TypedArrayrefByteOffSetFuzzerTest(data, size); + OHOS::TypedArrayrefGetArrayBufferFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/typedarrayref_fuzzer/typedarrayref_fuzzer.h b/test/fuzztest/typedarrayref_fuzzer/typedarrayref_fuzzer.h new file mode 100644 index 0000000000..67b7a24be4 --- /dev/null +++ b/test/fuzztest/typedarrayref_fuzzer/typedarrayref_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TYPEDARRAYREF_FUZZER_H +#define TYPEDARRAYREF_FUZZER_H + +#define FUZZ_PROJECT_NAME "typedarrayref_fuzzer.h" + +#endif \ No newline at end of file