fix fuzztest errro and add new fuzztest

Signed-off-by: zhaozhibo <zhaozhibo3@huawei.com>
This commit is contained in:
zhaozhibo 2022-07-19 19:26:40 +08:00
parent a6896a6bce
commit 57c6b5df3f
35 changed files with 1020 additions and 44 deletions

View File

@ -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" ]
}
}
}
}

View File

@ -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",
]
}

View 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" ]
}

View 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;
}

View 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

View 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

View 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>

View 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" ]
}

View 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 "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;
}

View 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

View 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

View 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>

View 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" ]
}

View 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

View 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 "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;
}

View 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

View 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>

View File

@ -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);
}
}

View File

@ -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);
}
}

View 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" ]
}

View 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

View 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;
}

View 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

View 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>

View File

@ -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);
}
}

View 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" ]
}

View 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

View File

@ -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;
}

View 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 NEWBIGINTBYINT64_FUZZER_H
#define NEWBIGINTBYINT64_FUZZER_H
#define FUZZ_PROJECT_NAME "newbigintbyint64_fuzzer.h"
#endif

View 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>

View 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" ]
}

View 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

View File

@ -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;
}

View 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 NEWBIGINTBYUINT64_FUZZER_H
#define NEWBIGINTBYUINT64_FUZZER_H
#define FUZZ_PROJECT_NAME "newbigintbyuint64_fuzzer.h"
#endif

View 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>