mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
fix fuzztest errro and add new fuzztest
Signed-off-by: zhaozhibo <zhaozhibo3@huawei.com>
This commit is contained in:
parent
a6896a6bce
commit
57c6b5df3f
6
BUILD.gn
6
BUILD.gn
@ -78,6 +78,7 @@ if (defined(ark_standalone_build)) {
|
||||
"//arkcompiler/ets_runtime/ecmascript/tooling/test:unittest",
|
||||
"//arkcompiler/ets_runtime/ecmascript/ts_types/tests:unittest",
|
||||
]
|
||||
deps += [ "//arkcompiler/ets_runtime/test/fuzztest:fuzztest" ]
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,11 +117,6 @@ if (defined(ark_standalone_build)) {
|
||||
deps +=
|
||||
[ "//arkcompiler/ets_runtime/test/typeinfer:ark_typeinfer_test" ]
|
||||
}
|
||||
|
||||
# fuzz test
|
||||
if (is_standard_system) {
|
||||
deps += [ "//arkcompiler/ets_runtime/test/fuzztest:fuzztest" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,14 @@ group("fuzztest") {
|
||||
deps = []
|
||||
|
||||
deps += [
|
||||
"biginttoint64_fuzzer:fuzztest",
|
||||
"biginttouint64_fuzzer:fuzztest",
|
||||
"createbigwords_fuzzer:fuzztest",
|
||||
"dispatchprotocolmessage_fuzzer:fuzztest",
|
||||
"execute_fuzzer:fuzztest",
|
||||
"getwordsarray_fuzzer:fuzztest",
|
||||
"initializedebugger_fuzzer:fuzztest",
|
||||
"newbigintbyint64_fuzzer:fuzztest",
|
||||
"newbigintbyuint64_fuzzer:fuzztest",
|
||||
]
|
||||
}
|
||||
|
43
test/fuzztest/biginttoint64_fuzzer/BUILD.gn
Normal file
43
test/fuzztest/biginttoint64_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//build/test.gni")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("BigIntToInt64FuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file =
|
||||
"//arkcompiler/ets_runtime/test/fuzztest/biginttoint64_fuzzer"
|
||||
|
||||
sources = [ "biginttoint64_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//arkcompiler/ets_runtime:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":BigIntToInt64FuzzTest" ]
|
||||
}
|
55
test/fuzztest/biginttoint64_fuzzer/biginttoint64_fuzzer.cpp
Normal file
55
test/fuzztest/biginttoint64_fuzzer/biginttoint64_fuzzer.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "biginttoint64_fuzzer.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void BigIntToInt64FuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
int64_t input = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
Local<BigIntRef> bigint = BigIntRef::New(vm, input);
|
||||
|
||||
int64_t cValue = 0;
|
||||
bool lossless = false;
|
||||
bigint->BigIntToInt64(vm, &cValue, &lossless);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::BigIntToInt64FuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
21
test/fuzztest/biginttoint64_fuzzer/biginttoint64_fuzzer.h
Normal file
21
test/fuzztest/biginttoint64_fuzzer/biginttoint64_fuzzer.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 BIGINTTOINT64_FUZZER_H
|
||||
#define BIGINTTOINT64_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "biginttoint64_fuzzer.h"
|
||||
|
||||
#endif
|
14
test/fuzztest/biginttoint64_fuzzer/corpus/init
Normal file
14
test/fuzztest/biginttoint64_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2021 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
|
25
test/fuzztest/biginttoint64_fuzzer/project.xml
Normal file
25
test/fuzztest/biginttoint64_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
43
test/fuzztest/biginttouint64_fuzzer/BUILD.gn
Normal file
43
test/fuzztest/biginttouint64_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//build/test.gni")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("BigIntToUint64FuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file =
|
||||
"//arkcompiler/ets_runtime/test/fuzztest/biginttouint64_fuzzer"
|
||||
|
||||
sources = [ "biginttouint64_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//arkcompiler/ets_runtime:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":BigIntToUint64FuzzTest" ]
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "biginttouint64_fuzzer.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void BigIntToUint64FuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
uint64_t input = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
Local<BigIntRef> bigint = BigIntRef::New(vm, input);
|
||||
|
||||
uint64_t cValue = 0;
|
||||
bool lossless = false;
|
||||
bigint->BigIntToUint64(vm, &cValue, &lossless);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::BigIntToUint64FuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
21
test/fuzztest/biginttouint64_fuzzer/biginttouint64_fuzzer.h
Normal file
21
test/fuzztest/biginttouint64_fuzzer/biginttouint64_fuzzer.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 BIGINTTOUINT64_FUZZER_H
|
||||
#define BIGINTTOUINT64_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "biginttouint64_fuzzer.h"
|
||||
|
||||
#endif
|
14
test/fuzztest/biginttouint64_fuzzer/corpus/init
Normal file
14
test/fuzztest/biginttouint64_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2021 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
|
25
test/fuzztest/biginttouint64_fuzzer/project.xml
Normal file
25
test/fuzztest/biginttouint64_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
43
test/fuzztest/createbigwords_fuzzer/BUILD.gn
Normal file
43
test/fuzztest/createbigwords_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//build/test.gni")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("CreateBigWordsFuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file =
|
||||
"//arkcompiler/ets_runtime/test/fuzztest/createbigwords_fuzzer"
|
||||
|
||||
sources = [ "createbigwords_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//arkcompiler/ets_runtime:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":CreateBigWordsFuzzTest" ]
|
||||
}
|
14
test/fuzztest/createbigwords_fuzzer/corpus/init
Normal file
14
test/fuzztest/createbigwords_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2021 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
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "createbigwords_fuzzer.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void CreateBigWordsFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if (!size) {
|
||||
return;
|
||||
}
|
||||
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
bool sign = true;
|
||||
const size_t uint64BytesNum = 8;
|
||||
if (size < uint64BytesNum) {
|
||||
uint64_t words = 0;
|
||||
if (memcpy_s(&words, uint64BytesNum, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
BigIntRef::CreateBigWords(vm, sign, 1U, &words); // 1 : single word
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t wordsNum = size / uint64BytesNum;
|
||||
size_t hasRemain = size % uint64BytesNum;
|
||||
if (hasRemain) {
|
||||
wordsNum++;
|
||||
}
|
||||
std::vector<uint64_t> wordsVec;
|
||||
size_t count = uint64BytesNum;
|
||||
for (uint32_t i = 0; i < wordsNum; i++) {
|
||||
uint64_t word = 0;
|
||||
if (hasRemain && (i == (wordsNum - 1U))) {
|
||||
count = hasRemain;
|
||||
}
|
||||
if (memcpy_s(&word, uint64BytesNum, data, count) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
wordsVec.push_back(word);
|
||||
data += count;
|
||||
}
|
||||
uint64_t *words = new uint64_t[wordsNum]();
|
||||
std::copy(wordsVec.begin(), wordsVec.end(), words);
|
||||
BigIntRef::CreateBigWords(vm, sign, wordsNum, words);
|
||||
delete[] words;
|
||||
words = nullptr;
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::CreateBigWordsFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
21
test/fuzztest/createbigwords_fuzzer/createbigwords_fuzzer.h
Normal file
21
test/fuzztest/createbigwords_fuzzer/createbigwords_fuzzer.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 CREATEBIGWORDS_FUZZER_H
|
||||
#define CREATEBIGWORDS_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "createbigwords_fuzzer.h"
|
||||
|
||||
#endif
|
25
test/fuzztest/createbigwords_fuzzer/project.xml
Normal file
25
test/fuzztest/createbigwords_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -14,8 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "dispatchprotocolmessage_fuzzer.h"
|
||||
#include<cstddef>
|
||||
#include<cstdint>
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/tooling/debugger_service.h"
|
||||
|
||||
@ -23,20 +21,16 @@ using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::tooling;
|
||||
|
||||
bool createstatus = true;
|
||||
namespace OHOS {
|
||||
bool DispatchProtocolMessageFuzzTest(const uint8_t* data, size_t size)
|
||||
void DispatchProtocolMessageFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
if (createstatus) {
|
||||
JSNApi::CreateJSVM(option);
|
||||
createstatus = false;
|
||||
}
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
auto jsvm = JSNApi::CreateJSVM(option);
|
||||
auto vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
std::string message(data, data+size);
|
||||
panda::ecmascript::tooling::DispatchMessage(jsvm, std::move(message));
|
||||
return true;
|
||||
DispatchMessage(vm, std::move(message));
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,31 +15,24 @@
|
||||
|
||||
#include "execute_fuzzer.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "unistd.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
bool createstatus = true;
|
||||
namespace OHOS {
|
||||
// staic constexpr auto PANDA_MAIN_PATH = "pandastdlib/pandastdlib.bin";
|
||||
static constexpr auto PANDA_MAIN_FUNCTION = "_GLOBAL::func_main_0";
|
||||
|
||||
bool ExecuteFuzzTest(const uint8_t* data, size_t size)
|
||||
void ExecuteFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
if (createstatus) {
|
||||
JSNApi::CreateJSVM(option);
|
||||
createstatus = false;
|
||||
}
|
||||
|
||||
option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
auto jsvm = JSNApi::CreateJSVM(option);
|
||||
Local<StringRef> entry = StringRef::NewFromUtf8(jsvm, PANDA_MAIN_FUNCTION);
|
||||
auto vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
Local<StringRef> entry = StringRef::NewFromUtf8(vm, PANDA_MAIN_FUNCTION);
|
||||
std::string a = entry->StringRef::ToString();
|
||||
JSNApi::Execute(jsvm, data, size, a);
|
||||
JSNApi::DestroyJSVM(jsvm);
|
||||
return true;
|
||||
JSNApi::Execute(vm, data, size, a);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
|
43
test/fuzztest/getwordsarray_fuzzer/BUILD.gn
Normal file
43
test/fuzztest/getwordsarray_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//build/test.gni")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("GetWordsArrayFuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file =
|
||||
"//arkcompiler/ets_runtime/test/fuzztest/getwordsarray_fuzzer"
|
||||
|
||||
sources = [ "getwordsarray_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//arkcompiler/ets_runtime:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":GetWordsArrayFuzzTest" ]
|
||||
}
|
14
test/fuzztest/getwordsarray_fuzzer/corpus/init
Normal file
14
test/fuzztest/getwordsarray_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2021 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
|
83
test/fuzztest/getwordsarray_fuzzer/getwordsarray_fuzzer.cpp
Normal file
83
test/fuzztest/getwordsarray_fuzzer/getwordsarray_fuzzer.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "getwordsarray_fuzzer.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
bool GetWordsArrayFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
bool sign = true;
|
||||
const size_t uint64BytesNum = 8;
|
||||
if (size < uint64BytesNum) {
|
||||
uint64_t words = 0;
|
||||
if (memcpy_s(&words, uint64BytesNum, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
Local<JSValueRef> bigWordsValue = BigIntRef::CreateBigWords(vm, sign, 1U, &words); // 1 : single word
|
||||
uint64_t *wordsArray = new uint64_t[1]();
|
||||
Local<BigIntRef> bigWords(bigWordsValue);
|
||||
bigWords->GetWordsArray(&sign, 1U, wordsArray);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t wordsNum = size / uint64BytesNum;
|
||||
size_t hasRemain = size % uint64BytesNum;
|
||||
if (hasRemain) {
|
||||
wordsNum++;
|
||||
}
|
||||
std::vector<uint64_t> wordsVec;
|
||||
size_t count = uint64BytesNum;
|
||||
for (uint32_t i = 0; i < wordsNum; i++) {
|
||||
uint64_t word = 0;
|
||||
if (hasRemain && (i == (wordsNum - 1U))) {
|
||||
count = hasRemain;
|
||||
}
|
||||
if (memcpy_s(&word, uint64BytesNum, data, count) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
wordsVec.push_back(word);
|
||||
data += count;
|
||||
}
|
||||
uint64_t *words = new uint64_t[wordsNum]();
|
||||
std::copy(wordsVec.begin(), wordsVec.end(), words);
|
||||
Local<JSValueRef> bigWordsValue = BigIntRef::CreateBigWords(vm, sign, wordsNum, words);
|
||||
uint64_t *wordsArray = new uint64_t[wordsNum]();
|
||||
Local<BigIntRef> bigWords(bigWordsValue);
|
||||
bigWords->GetWordsArray(&sign, wordsNum, wordsArray);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::GetWordsArrayFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
21
test/fuzztest/getwordsarray_fuzzer/getwordsarray_fuzzer.h
Normal file
21
test/fuzztest/getwordsarray_fuzzer/getwordsarray_fuzzer.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 GETWORDSARRAY_FUZZER_H
|
||||
#define GETWORDSARRAY_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "getwordsarray_fuzzer.h"
|
||||
|
||||
#endif
|
25
test/fuzztest/getwordsarray_fuzzer/project.xml
Normal file
25
test/fuzztest/getwordsarray_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
@ -14,36 +14,27 @@
|
||||
*/
|
||||
|
||||
#include "initializedebugger_fuzzer.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/tooling/debugger_service.h"
|
||||
#include "ecmascript/tooling/protocol_handler.h"
|
||||
#include "unistd.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::tooling;
|
||||
|
||||
bool createstatus = true;
|
||||
namespace OHOS {
|
||||
bool InitializeDebuggerFuzzTest(const uint8_t* data, size_t size)
|
||||
void InitializeDebuggerFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
if (createstatus) {
|
||||
JSNApi::CreateJSVM(option);
|
||||
createstatus = false;
|
||||
}
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
auto jsvm = JSNApi::CreateJSVM(option);
|
||||
auto vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
using OnResponseType = const std::function<void(const void *, const std::string &)>;
|
||||
OnResponseType onResponse = [data, size](const void *d, [[maybe_unused]] const std::string &s) -> void {
|
||||
d = data + size;
|
||||
};
|
||||
panda::ecmascript::tooling::InitializeDebugger(jsvm, onResponse);
|
||||
panda::ecmascript::tooling::UninitializeDebugger(jsvm);
|
||||
JSNApi::DestroyJSVM(jsvm);
|
||||
return true;
|
||||
InitializeDebugger(vm, onResponse);
|
||||
UninitializeDebugger(vm);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
|
43
test/fuzztest/newbigintbyint64_fuzzer/BUILD.gn
Normal file
43
test/fuzztest/newbigintbyint64_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//build/test.gni")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("NewBigIntByInt64FuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file =
|
||||
"//arkcompiler/ets_runtime/test/fuzztest/newbigintbyint64_fuzzer"
|
||||
|
||||
sources = [ "newbigintbyint64_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//arkcompiler/ets_runtime:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":NewBigIntByInt64FuzzTest" ]
|
||||
}
|
14
test/fuzztest/newbigintbyint64_fuzzer/corpus/init
Normal file
14
test/fuzztest/newbigintbyint64_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2021 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
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "newbigintbyint64_fuzzer.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void NewBigIntByInt64FuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
int64_t input = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
BigIntRef::New(vm, input);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::NewBigIntByInt64FuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 NEWBIGINTBYINT64_FUZZER_H
|
||||
#define NEWBIGINTBYINT64_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "newbigintbyint64_fuzzer.h"
|
||||
|
||||
#endif
|
25
test/fuzztest/newbigintbyint64_fuzzer/project.xml
Normal file
25
test/fuzztest/newbigintbyint64_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
43
test/fuzztest/newbigintbyuint64_fuzzer/BUILD.gn
Normal file
43
test/fuzztest/newbigintbyuint64_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//build/test.gni")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("NewBigIntByUint64FuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file =
|
||||
"//arkcompiler/ets_runtime/test/fuzztest/newbigintbyuint64_fuzzer"
|
||||
|
||||
sources = [ "newbigintbyuint64_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//arkcompiler/ets_runtime:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":NewBigIntByUint64FuzzTest" ]
|
||||
}
|
14
test/fuzztest/newbigintbyuint64_fuzzer/corpus/init
Normal file
14
test/fuzztest/newbigintbyuint64_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2021 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
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "ecmascript/napi/include/jsnapi.h"
|
||||
#include "ecmascript/log_wrapper.h"
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "newbigintbyuint64_fuzzer.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void NewBigIntByUint64FuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
[[maybe_unused]] LocalScope scope(vm);
|
||||
uint64_t input = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&input, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
BigIntRef::New(vm, input);
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::NewBigIntByUint64FuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 NEWBIGINTBYUINT64_FUZZER_H
|
||||
#define NEWBIGINTBYUINT64_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "newbigintbyuint64_fuzzer.h"
|
||||
|
||||
#endif
|
25
test/fuzztest/newbigintbyuint64_fuzzer/project.xml
Normal file
25
test/fuzztest/newbigintbyuint64_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2022 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_config>
|
||||
<fuzztest>
|
||||
<!-- maximum length of a test input -->
|
||||
<max_len>1000</max_len>
|
||||
<!-- maximum total time in seconds to run the fuzzer -->
|
||||
<max_total_time>300</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
Loading…
Reference in New Issue
Block a user