已合并
fix fuzztest errro and add new fuzztest #1833
AtomGit-Bot创建于 2022年7月19日
fix fuzztest errro and add new fuzztest #1833
已合并
共 35 个文件变更+1020-44
| @@ -78,6 +78,7 @@ if (defined(ark_standalone_build)) { | |||
| 78 | "//arkcompiler/ets_runtime/ecmascript/tooling/test:unittest", | 78 | "//arkcompiler/ets_runtime/ecmascript/tooling/test:unittest", |
| 79 | "//arkcompiler/ets_runtime/ecmascript/ts_types/tests:unittest", | 79 | "//arkcompiler/ets_runtime/ecmascript/ts_types/tests:unittest", |
| 80 | ] | 80 | ] |
| 81 | + deps += [ "//arkcompiler/ets_runtime/test/fuzztest:fuzztest" ] | ||
| 81 | } | 82 | } |
| 82 | } | 83 | } |
| 83 | 84 | ||
| @@ -116,11 +117,6 @@ if (defined(ark_standalone_build)) { | |||
| 116 | deps += | 117 | deps += |
| 117 | [ "//arkcompiler/ets_runtime/test/typeinfer:ark_typeinfer_test" ] | 118 | [ "//arkcompiler/ets_runtime/test/typeinfer:ark_typeinfer_test" ] |
| 118 | } | 119 | } |
| 119 | - | ||
| 120 | - # fuzz test | ||
| 121 | - if (is_standard_system) { | ||
| 122 | - deps += [ "//arkcompiler/ets_runtime/test/fuzztest:fuzztest" ] | ||
| 123 | - } | ||
| 124 | } | 120 | } |
| 125 | } | 121 | } |
| 126 | } | 122 | } |
| @@ -16,8 +16,14 @@ group("fuzztest") { | |||
| 16 | deps = [] | 16 | deps = [] |
| 17 | 17 | ||
| 18 | deps += [ | 18 | deps += [ |
| 19 | + "biginttoint64_fuzzer:fuzztest", | ||
| 20 | + "biginttouint64_fuzzer:fuzztest", | ||
| 21 | + "createbigwords_fuzzer:fuzztest", | ||
| 19 | "dispatchprotocolmessage_fuzzer:fuzztest", | 22 | "dispatchprotocolmessage_fuzzer:fuzztest", |
| 20 | "execute_fuzzer:fuzztest", | 23 | "execute_fuzzer:fuzztest", |
| 24 | + "getwordsarray_fuzzer:fuzztest", | ||
| 21 | "initializedebugger_fuzzer:fuzztest", | 25 | "initializedebugger_fuzzer:fuzztest", |
| 26 | + "newbigintbyint64_fuzzer:fuzztest", | ||
| 27 | + "newbigintbyuint64_fuzzer:fuzztest", | ||
| 22 | ] | 28 | ] |
| 23 | } | 29 | } |
| @@ -0,0 +1,43 @@ | |||
| 1 | +# Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################################hydra-fuzz############################### | ||
| 15 | +import("//arkcompiler/ets_runtime/js_runtime_config.gni") | ||
| 16 | +import("//arkcompiler/ets_runtime/test/test_helper.gni") | ||
| 17 | +import("//build/config/features.gni") | ||
| 18 | +import("//build/ohos.gni") | ||
| 19 | +import("//build/test.gni") | ||
| 20 | + | ||
| 21 | +####################################fuzztest################################## | ||
| 22 | +ohos_fuzztest("BigIntToInt64FuzzTest") { | ||
| 23 | + module_out_path = "arkcompiler/ets_runtime" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = | ||
| 26 | + "//arkcompiler/ets_runtime/test/fuzztest/biginttoint64_fuzzer" | ||
| 27 | + | ||
| 28 | + sources = [ "biginttoint64_fuzzer.cpp" ] | ||
| 29 | + | ||
| 30 | + configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] | ||
| 31 | + | ||
| 32 | + deps = [ | ||
| 33 | + "$ark_root/libpandabase:libarkbase", | ||
| 34 | + "//arkcompiler/ets_runtime:libark_jsruntime", | ||
| 35 | + sdk_libc_secshared_dep, | ||
| 36 | + ] | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +group("fuzztest") { | ||
| 40 | + testonly = true | ||
| 41 | + deps = [] | ||
| 42 | + deps += [ ":BigIntToInt64FuzzTest" ] | ||
| 43 | +} | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace panda; | ||
| 22 | +using namespace panda::ecmascript; | ||
| 23 | + | ||
| 24 | +namespace OHOS { | ||
| 25 | + void BigIntToInt64FuzzTest(const uint8_t* data, size_t size) | ||
| 26 | + { | ||
| 27 | + RuntimeOption option; | ||
| 28 | + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | ||
| 29 | + EcmaVM *vm = JSNApi::CreateJSVM(option); | ||
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 31 | + int64_t input = 0; | ||
| 32 | + size_t maxByteLen = 8; | ||
| 33 | + if (size > maxByteLen) { | ||
| 34 | + size = maxByteLen; | ||
| 35 | + } | ||
| 36 | + if (memcpy_s(&input, maxByteLen, data, size) != EOK) { | ||
| 37 | + std::cout << "memcpy_s failed!"; | ||
| 38 | + UNREACHABLE(); | ||
| 39 | + } | ||
| 40 | + Local<BigIntRef> bigint = BigIntRef::New(vm, input); | ||
| 41 | + | ||
| 42 | + int64_t cValue = 0; | ||
| 43 | + bool lossless = false; | ||
| 44 | + bigint->BigIntToInt64(vm, &cValue, &lossless); | ||
| 45 | + JSNApi::DestroyJSVM(vm); | ||
| 46 | + } | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +// Fuzzer entry point. | ||
| 50 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 51 | +{ | ||
| 52 | + // Run your code on data. | ||
| 53 | + OHOS::BigIntToInt64FuzzTest(data, size); | ||
| 54 | + return 0; | ||
| 55 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +# Copyright (c) 2021 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +FUZZ | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | + | ||
| 2 | +<!-- Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -0,0 +1,43 @@ | |||
| 1 | +# Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################################hydra-fuzz############################### | ||
| 15 | +import("//arkcompiler/ets_runtime/js_runtime_config.gni") | ||
| 16 | +import("//arkcompiler/ets_runtime/test/test_helper.gni") | ||
| 17 | +import("//build/config/features.gni") | ||
| 18 | +import("//build/ohos.gni") | ||
| 19 | +import("//build/test.gni") | ||
| 20 | + | ||
| 21 | +####################################fuzztest################################## | ||
| 22 | +ohos_fuzztest("BigIntToUint64FuzzTest") { | ||
| 23 | + module_out_path = "arkcompiler/ets_runtime" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = | ||
| 26 | + "//arkcompiler/ets_runtime/test/fuzztest/biginttouint64_fuzzer" | ||
| 27 | + | ||
| 28 | + sources = [ "biginttouint64_fuzzer.cpp" ] | ||
| 29 | + | ||
| 30 | + configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] | ||
| 31 | + | ||
| 32 | + deps = [ | ||
| 33 | + "$ark_root/libpandabase:libarkbase", | ||
| 34 | + "//arkcompiler/ets_runtime:libark_jsruntime", | ||
| 35 | + sdk_libc_secshared_dep, | ||
| 36 | + ] | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +group("fuzztest") { | ||
| 40 | + testonly = true | ||
| 41 | + deps = [] | ||
| 42 | + deps += [ ":BigIntToUint64FuzzTest" ] | ||
| 43 | +} | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace panda; | ||
| 22 | +using namespace panda::ecmascript; | ||
| 23 | + | ||
| 24 | +namespace OHOS { | ||
| 25 | + void BigIntToUint64FuzzTest(const uint8_t* data, size_t size) | ||
| 26 | + { | ||
| 27 | + RuntimeOption option; | ||
| 28 | + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | ||
| 29 | + EcmaVM *vm = JSNApi::CreateJSVM(option); | ||
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 31 | + uint64_t input = 0; | ||
| 32 | + size_t maxByteLen = 8; | ||
| 33 | + if (size > maxByteLen) { | ||
| 34 | + size = maxByteLen; | ||
| 35 | + } | ||
| 36 | + if (memcpy_s(&input, maxByteLen, data, size) != EOK) { | ||
| 37 | + std::cout << "memcpy_s failed!"; | ||
| 38 | + UNREACHABLE(); | ||
| 39 | + } | ||
| 40 | + Local<BigIntRef> bigint = BigIntRef::New(vm, input); | ||
| 41 | + | ||
| 42 | + uint64_t cValue = 0; | ||
| 43 | + bool lossless = false; | ||
| 44 | + bigint->BigIntToUint64(vm, &cValue, &lossless); | ||
| 45 | + JSNApi::DestroyJSVM(vm); | ||
| 46 | + } | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +// Fuzzer entry point. | ||
| 50 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 51 | +{ | ||
| 52 | + // Run your code on data. | ||
| 53 | + OHOS::BigIntToUint64FuzzTest(data, size); | ||
| 54 | + return 0; | ||
| 55 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +# Copyright (c) 2021 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +FUZZ | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | + | ||
| 2 | +<!-- Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -0,0 +1,43 @@ | |||
| 1 | +# Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################################hydra-fuzz############################### | ||
| 15 | +import("//arkcompiler/ets_runtime/js_runtime_config.gni") | ||
| 16 | +import("//arkcompiler/ets_runtime/test/test_helper.gni") | ||
| 17 | +import("//build/config/features.gni") | ||
| 18 | +import("//build/ohos.gni") | ||
| 19 | +import("//build/test.gni") | ||
| 20 | + | ||
| 21 | +####################################fuzztest################################## | ||
| 22 | +ohos_fuzztest("CreateBigWordsFuzzTest") { | ||
| 23 | + module_out_path = "arkcompiler/ets_runtime" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = | ||
| 26 | + "//arkcompiler/ets_runtime/test/fuzztest/createbigwords_fuzzer" | ||
| 27 | + | ||
| 28 | + sources = [ "createbigwords_fuzzer.cpp" ] | ||
| 29 | + | ||
| 30 | + configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] | ||
| 31 | + | ||
| 32 | + deps = [ | ||
| 33 | + "$ark_root/libpandabase:libarkbase", | ||
| 34 | + "//arkcompiler/ets_runtime:libark_jsruntime", | ||
| 35 | + sdk_libc_secshared_dep, | ||
| 36 | + ] | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +group("fuzztest") { | ||
| 40 | + testonly = true | ||
| 41 | + deps = [] | ||
| 42 | + deps += [ ":CreateBigWordsFuzzTest" ] | ||
| 43 | +} | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +# Copyright (c) 2021 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +FUZZ | ||
| @@ -0,0 +1,83 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace panda; | ||
| 22 | +using namespace panda::ecmascript; | ||
| 23 | + | ||
| 24 | +namespace OHOS { | ||
| 25 | + void CreateBigWordsFuzzTest(const uint8_t* data, size_t size) | ||
| 26 | + { | ||
| 27 | + if (!size) { | ||
| 28 | + return; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + RuntimeOption option; | ||
| 32 | + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | ||
| 33 | + EcmaVM *vm = JSNApi::CreateJSVM(option); | ||
| 34 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 35 | + bool sign = true; | ||
| 36 | + const size_t uint64BytesNum = 8; | ||
| 37 | + if (size < uint64BytesNum) { | ||
| 38 | + uint64_t words = 0; | ||
| 39 | + if (memcpy_s(&words, uint64BytesNum, data, size) != EOK) { | ||
| 40 | + std::cout << "memcpy_s failed!"; | ||
| 41 | + UNREACHABLE(); | ||
| 42 | + } | ||
| 43 | + BigIntRef::CreateBigWords(vm, sign, 1U, &words); // 1 : single word | ||
| 44 | + JSNApi::DestroyJSVM(vm); | ||
| 45 | + return; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + size_t wordsNum = size / uint64BytesNum; | ||
| 49 | + size_t hasRemain = size % uint64BytesNum; | ||
| 50 | + if (hasRemain) { | ||
| 51 | + wordsNum++; | ||
| 52 | + } | ||
| 53 | + std::vector<uint64_t> wordsVec; | ||
| 54 | + size_t count = uint64BytesNum; | ||
| 55 | + for (uint32_t i = 0; i < wordsNum; i++) { | ||
| 56 | + uint64_t word = 0; | ||
| 57 | + if (hasRemain && (i == (wordsNum - 1U))) { | ||
| 58 | + count = hasRemain; | ||
| 59 | + } | ||
| 60 | + if (memcpy_s(&word, uint64BytesNum, data, count) != EOK) { | ||
| 61 | + std::cout << "memcpy_s failed!"; | ||
| 62 | + UNREACHABLE(); | ||
| 63 | + } | ||
| 64 | + wordsVec.push_back(word); | ||
| 65 | + data += count; | ||
| 66 | + } | ||
| 67 | + uint64_t *words = new uint64_t[wordsNum](); | ||
| 68 | + std::copy(wordsVec.begin(), wordsVec.end(), words); | ||
| 69 | + BigIntRef::CreateBigWords(vm, sign, wordsNum, words); | ||
| 70 | + delete[] words; | ||
| 71 | + words = nullptr; | ||
| 72 | + JSNApi::DestroyJSVM(vm); | ||
| 73 | + return; | ||
| 74 | + } | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +// Fuzzer entry point. | ||
| 78 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 79 | +{ | ||
| 80 | + // Run your code on data. | ||
| 81 | + OHOS::CreateBigWordsFuzzTest(data, size); | ||
| 82 | + return 0; | ||
| 83 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | + | ||
| 2 | +<!-- Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -14,8 +14,6 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | - | ||
| 18 | - | ||
| 19 | 17 | ||
| 20 | 18 | ||
| 21 | 19 | ||
| @@ -23,20 +21,16 @@ using namespace panda; | |||
| 23 | using namespace panda::ecmascript; | 21 | using namespace panda::ecmascript; |
| 24 | using namespace panda::ecmascript::tooling; | 22 | using namespace panda::ecmascript::tooling; |
| 25 | 23 | ||
| 26 | -bool createstatus = true; | ||
| 27 | namespace OHOS { | 24 | namespace OHOS { |
| 28 | - bool DispatchProtocolMessageFuzzTest(const uint8_t* data, size_t size) | 25 | + void DispatchProtocolMessageFuzzTest(const uint8_t* data, size_t size) |
| 29 | { | 26 | { |
| 30 | RuntimeOption option; | 27 | RuntimeOption option; |
| 31 | - if (createstatus) { | ||
| 32 | - JSNApi::CreateJSVM(option); | ||
| 33 | - createstatus = false; | ||
| 34 | - } | ||
| 35 | option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | 28 | option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); |
| 36 | - auto jsvm = JSNApi::CreateJSVM(option); | 29 | + auto vm = JSNApi::CreateJSVM(option); |
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 37 | std::string message(data, data+size); | 31 | std::string message(data, data+size); |
| 38 | - panda::ecmascript::tooling::DispatchMessage(jsvm, std::move(message)); | 32 | + DispatchMessage(vm, std::move(message)); |
| 39 | - return true; | 33 | + JSNApi::DestroyJSVM(vm); |
| 40 | } | 34 | } |
| 41 | } | 35 | } |
| 42 | 36 | ||
| @@ -15,31 +15,24 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | - | ||
| 19 | 18 | ||
| 20 | using namespace panda; | 19 | using namespace panda; |
| 21 | using namespace panda::ecmascript; | 20 | using namespace panda::ecmascript; |
| 22 | -bool createstatus = true; | ||
| 23 | namespace OHOS { | 21 | namespace OHOS { |
| 24 | // staic constexpr auto PANDA_MAIN_PATH = "pandastdlib/pandastdlib.bin"; | 22 | // staic constexpr auto PANDA_MAIN_PATH = "pandastdlib/pandastdlib.bin"; |
| 25 | static constexpr auto PANDA_MAIN_FUNCTION = "_GLOBAL::func_main_0"; | 23 | static constexpr auto PANDA_MAIN_FUNCTION = "_GLOBAL::func_main_0"; |
| 26 | 24 | ||
| 27 | - bool ExecuteFuzzTest(const uint8_t* data, size_t size) | 25 | + void ExecuteFuzzTest(const uint8_t* data, size_t size) |
| 28 | { | 26 | { |
| 29 | RuntimeOption option; | 27 | RuntimeOption option; |
| 30 | - if (createstatus) { | ||
| 31 | - JSNApi::CreateJSVM(option); | ||
| 32 | - createstatus = false; | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); | 28 | option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC); |
| 36 | option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | 29 | option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); |
| 37 | - auto jsvm = JSNApi::CreateJSVM(option); | 30 | + auto vm = JSNApi::CreateJSVM(option); |
| 38 | - Local<StringRef> entry = StringRef::NewFromUtf8(jsvm, PANDA_MAIN_FUNCTION); | 31 | + [[maybe_unused]] LocalScope scope(vm); |
| 32 | + Local<StringRef> entry = StringRef::NewFromUtf8(vm, PANDA_MAIN_FUNCTION); | ||
| 39 | std::string a = entry->StringRef::ToString(); | 33 | std::string a = entry->StringRef::ToString(); |
| 40 | - JSNApi::Execute(jsvm, data, size, a); | 34 | + JSNApi::Execute(vm, data, size, a); |
| 41 | - JSNApi::DestroyJSVM(jsvm); | 35 | + JSNApi::DestroyJSVM(vm); |
| 42 | - return true; | ||
| 43 | } | 36 | } |
| 44 | } | 37 | } |
| 45 | 38 | ||
| @@ -0,0 +1,43 @@ | |||
| 1 | +# Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################################hydra-fuzz############################### | ||
| 15 | +import("//arkcompiler/ets_runtime/js_runtime_config.gni") | ||
| 16 | +import("//arkcompiler/ets_runtime/test/test_helper.gni") | ||
| 17 | +import("//build/config/features.gni") | ||
| 18 | +import("//build/ohos.gni") | ||
| 19 | +import("//build/test.gni") | ||
| 20 | + | ||
| 21 | +####################################fuzztest################################## | ||
| 22 | +ohos_fuzztest("GetWordsArrayFuzzTest") { | ||
| 23 | + module_out_path = "arkcompiler/ets_runtime" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = | ||
| 26 | + "//arkcompiler/ets_runtime/test/fuzztest/getwordsarray_fuzzer" | ||
| 27 | + | ||
| 28 | + sources = [ "getwordsarray_fuzzer.cpp" ] | ||
| 29 | + | ||
| 30 | + configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] | ||
| 31 | + | ||
| 32 | + deps = [ | ||
| 33 | + "$ark_root/libpandabase:libarkbase", | ||
| 34 | + "//arkcompiler/ets_runtime:libark_jsruntime", | ||
| 35 | + sdk_libc_secshared_dep, | ||
| 36 | + ] | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +group("fuzztest") { | ||
| 40 | + testonly = true | ||
| 41 | + deps = [] | ||
| 42 | + deps += [ ":GetWordsArrayFuzzTest" ] | ||
| 43 | +} | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +# Copyright (c) 2021 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +FUZZ | ||
| @@ -0,0 +1,83 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace panda; | ||
| 22 | +using namespace panda::ecmascript; | ||
| 23 | + | ||
| 24 | +namespace OHOS { | ||
| 25 | + bool GetWordsArrayFuzzTest(const uint8_t* data, size_t size) | ||
| 26 | + { | ||
| 27 | + RuntimeOption option; | ||
| 28 | + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | ||
| 29 | + EcmaVM *vm = JSNApi::CreateJSVM(option); | ||
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 31 | + bool sign = true; | ||
| 32 | + const size_t uint64BytesNum = 8; | ||
| 33 | + if (size < uint64BytesNum) { | ||
| 34 | + uint64_t words = 0; | ||
| 35 | + if (memcpy_s(&words, uint64BytesNum, data, size) != EOK) { | ||
| 36 | + std::cout << "memcpy_s failed!"; | ||
| 37 | + UNREACHABLE(); | ||
| 38 | + } | ||
| 39 | + Local<JSValueRef> bigWordsValue = BigIntRef::CreateBigWords(vm, sign, 1U, &words); // 1 : single word | ||
| 40 | + uint64_t *wordsArray = new uint64_t[1](); | ||
| 41 | + Local<BigIntRef> bigWords(bigWordsValue); | ||
| 42 | + bigWords->GetWordsArray(&sign, 1U, wordsArray); | ||
| 43 | + JSNApi::DestroyJSVM(vm); | ||
| 44 | + return true; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + size_t wordsNum = size / uint64BytesNum; | ||
| 48 | + size_t hasRemain = size % uint64BytesNum; | ||
| 49 | + if (hasRemain) { | ||
| 50 | + wordsNum++; | ||
| 51 | + } | ||
| 52 | + std::vector<uint64_t> wordsVec; | ||
| 53 | + size_t count = uint64BytesNum; | ||
| 54 | + for (uint32_t i = 0; i < wordsNum; i++) { | ||
| 55 | + uint64_t word = 0; | ||
| 56 | + if (hasRemain && (i == (wordsNum - 1U))) { | ||
| 57 | + count = hasRemain; | ||
| 58 | + } | ||
| 59 | + if (memcpy_s(&word, uint64BytesNum, data, count) != EOK) { | ||
| 60 | + std::cout << "memcpy_s failed!"; | ||
| 61 | + UNREACHABLE(); | ||
| 62 | + } | ||
| 63 | + wordsVec.push_back(word); | ||
| 64 | + data += count; | ||
| 65 | + } | ||
| 66 | + uint64_t *words = new uint64_t[wordsNum](); | ||
| 67 | + std::copy(wordsVec.begin(), wordsVec.end(), words); | ||
| 68 | + Local<JSValueRef> bigWordsValue = BigIntRef::CreateBigWords(vm, sign, wordsNum, words); | ||
| 69 | + uint64_t *wordsArray = new uint64_t[wordsNum](); | ||
| 70 | + Local<BigIntRef> bigWords(bigWordsValue); | ||
| 71 | + bigWords->GetWordsArray(&sign, wordsNum, wordsArray); | ||
| 72 | + JSNApi::DestroyJSVM(vm); | ||
| 73 | + return true; | ||
| 74 | + } | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +// Fuzzer entry point. | ||
| 78 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 79 | +{ | ||
| 80 | + // Run your code on data. | ||
| 81 | + OHOS::GetWordsArrayFuzzTest(data, size); | ||
| 82 | + return 0; | ||
| 83 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | + | ||
| 2 | +<!-- Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -14,36 +14,27 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | - | ||
| 18 | - | ||
| 19 | 17 | ||
| 20 | 18 | ||
| 21 | - | ||
| 22 | - | ||
| 23 | 19 | ||
| 24 | using namespace panda; | 20 | using namespace panda; |
| 25 | using namespace panda::ecmascript; | 21 | using namespace panda::ecmascript; |
| 26 | using namespace panda::ecmascript::tooling; | 22 | using namespace panda::ecmascript::tooling; |
| 27 | 23 | ||
| 28 | -bool createstatus = true; | ||
| 29 | namespace OHOS { | 24 | namespace OHOS { |
| 30 | - bool InitializeDebuggerFuzzTest(const uint8_t* data, size_t size) | 25 | + void InitializeDebuggerFuzzTest(const uint8_t* data, size_t size) |
| 31 | { | 26 | { |
| 32 | RuntimeOption option; | 27 | RuntimeOption option; |
| 33 | - if (createstatus) { | ||
| 34 | - JSNApi::CreateJSVM(option); | ||
| 35 | - createstatus = false; | ||
| 36 | - } | ||
| 37 | option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | 28 | option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); |
| 38 | - auto jsvm = JSNApi::CreateJSVM(option); | 29 | + auto vm = JSNApi::CreateJSVM(option); |
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 39 | using OnResponseType = const std::function<void(const void *, const std::string &)>; | 31 | using OnResponseType = const std::function<void(const void *, const std::string &)>; |
| 40 | OnResponseType onResponse = [data, size](const void *d, [[maybe_unused]] const std::string &s) -> void { | 32 | OnResponseType onResponse = [data, size](const void *d, [[maybe_unused]] const std::string &s) -> void { |
| 41 | d = data + size; | 33 | d = data + size; |
| 42 | }; | 34 | }; |
| 43 | - panda::ecmascript::tooling::InitializeDebugger(jsvm, onResponse); | 35 | + InitializeDebugger(vm, onResponse); |
| 44 | - panda::ecmascript::tooling::UninitializeDebugger(jsvm); | 36 | + UninitializeDebugger(vm); |
| 45 | - JSNApi::DestroyJSVM(jsvm); | 37 | + JSNApi::DestroyJSVM(vm); |
| 46 | - return true; | ||
| 47 | } | 38 | } |
| 48 | } | 39 | } |
| 49 | 40 | ||
| @@ -0,0 +1,43 @@ | |||
| 1 | +# Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################################hydra-fuzz############################### | ||
| 15 | +import("//arkcompiler/ets_runtime/js_runtime_config.gni") | ||
| 16 | +import("//arkcompiler/ets_runtime/test/test_helper.gni") | ||
| 17 | +import("//build/config/features.gni") | ||
| 18 | +import("//build/ohos.gni") | ||
| 19 | +import("//build/test.gni") | ||
| 20 | + | ||
| 21 | +####################################fuzztest################################## | ||
| 22 | +ohos_fuzztest("NewBigIntByInt64FuzzTest") { | ||
| 23 | + module_out_path = "arkcompiler/ets_runtime" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = | ||
| 26 | + "//arkcompiler/ets_runtime/test/fuzztest/newbigintbyint64_fuzzer" | ||
| 27 | + | ||
| 28 | + sources = [ "newbigintbyint64_fuzzer.cpp" ] | ||
| 29 | + | ||
| 30 | + configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] | ||
| 31 | + | ||
| 32 | + deps = [ | ||
| 33 | + "$ark_root/libpandabase:libarkbase", | ||
| 34 | + "//arkcompiler/ets_runtime:libark_jsruntime", | ||
| 35 | + sdk_libc_secshared_dep, | ||
| 36 | + ] | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +group("fuzztest") { | ||
| 40 | + testonly = true | ||
| 41 | + deps = [] | ||
| 42 | + deps += [ ":NewBigIntByInt64FuzzTest" ] | ||
| 43 | +} | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +# Copyright (c) 2021 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +FUZZ | ||
| @@ -0,0 +1,51 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace panda; | ||
| 22 | +using namespace panda::ecmascript; | ||
| 23 | + | ||
| 24 | +namespace OHOS { | ||
| 25 | + void NewBigIntByInt64FuzzTest(const uint8_t* data, size_t size) | ||
| 26 | + { | ||
| 27 | + RuntimeOption option; | ||
| 28 | + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | ||
| 29 | + EcmaVM *vm = JSNApi::CreateJSVM(option); | ||
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 31 | + int64_t input = 0; | ||
| 32 | + size_t maxByteLen = 8; | ||
| 33 | + if (size > maxByteLen) { | ||
| 34 | + size = maxByteLen; | ||
| 35 | + } | ||
| 36 | + if (memcpy_s(&input, maxByteLen, data, size) != EOK) { | ||
| 37 | + std::cout << "memcpy_s failed!"; | ||
| 38 | + UNREACHABLE(); | ||
| 39 | + } | ||
| 40 | + BigIntRef::New(vm, input); | ||
| 41 | + JSNApi::DestroyJSVM(vm); | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +// Fuzzer entry point. | ||
| 46 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 47 | +{ | ||
| 48 | + // Run your code on data. | ||
| 49 | + OHOS::NewBigIntByInt64FuzzTest(data, size); | ||
| 50 | + return 0; | ||
| 51 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | + | ||
| 2 | +<!-- Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -0,0 +1,43 @@ | |||
| 1 | +# Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################################hydra-fuzz############################### | ||
| 15 | +import("//arkcompiler/ets_runtime/js_runtime_config.gni") | ||
| 16 | +import("//arkcompiler/ets_runtime/test/test_helper.gni") | ||
| 17 | +import("//build/config/features.gni") | ||
| 18 | +import("//build/ohos.gni") | ||
| 19 | +import("//build/test.gni") | ||
| 20 | + | ||
| 21 | +####################################fuzztest################################## | ||
| 22 | +ohos_fuzztest("NewBigIntByUint64FuzzTest") { | ||
| 23 | + module_out_path = "arkcompiler/ets_runtime" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = | ||
| 26 | + "//arkcompiler/ets_runtime/test/fuzztest/newbigintbyuint64_fuzzer" | ||
| 27 | + | ||
| 28 | + sources = [ "newbigintbyuint64_fuzzer.cpp" ] | ||
| 29 | + | ||
| 30 | + configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ] | ||
| 31 | + | ||
| 32 | + deps = [ | ||
| 33 | + "$ark_root/libpandabase:libarkbase", | ||
| 34 | + "//arkcompiler/ets_runtime:libark_jsruntime", | ||
| 35 | + sdk_libc_secshared_dep, | ||
| 36 | + ] | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +group("fuzztest") { | ||
| 40 | + testonly = true | ||
| 41 | + deps = [] | ||
| 42 | + deps += [ ":NewBigIntByUint64FuzzTest" ] | ||
| 43 | +} | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +# Copyright (c) 2021 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +FUZZ | ||
| @@ -0,0 +1,51 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace panda; | ||
| 22 | +using namespace panda::ecmascript; | ||
| 23 | + | ||
| 24 | +namespace OHOS { | ||
| 25 | + void NewBigIntByUint64FuzzTest(const uint8_t* data, size_t size) | ||
| 26 | + { | ||
| 27 | + RuntimeOption option; | ||
| 28 | + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); | ||
| 29 | + EcmaVM *vm = JSNApi::CreateJSVM(option); | ||
| 30 | + [[maybe_unused]] LocalScope scope(vm); | ||
| 31 | + uint64_t input = 0; | ||
| 32 | + size_t maxByteLen = 8; | ||
| 33 | + if (size > maxByteLen) { | ||
| 34 | + size = maxByteLen; | ||
| 35 | + } | ||
| 36 | + if (memcpy_s(&input, maxByteLen, data, size) != EOK) { | ||
| 37 | + std::cout << "memcpy_s failed!"; | ||
| 38 | + UNREACHABLE(); | ||
| 39 | + } | ||
| 40 | + BigIntRef::New(vm, input); | ||
| 41 | + JSNApi::DestroyJSVM(vm); | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +// Fuzzer entry point. | ||
| 46 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 47 | +{ | ||
| 48 | + // Run your code on data. | ||
| 49 | + OHOS::NewBigIntByUint64FuzzTest(data, size); | ||
| 50 | + return 0; | ||
| 51 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | + | ||
| 2 | +<!-- Copyright (c) 2022 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||