!770 fuzz testcases submit

Merge pull request !770 from wangjie/master
This commit is contained in:
openharmony_ci
2022-03-16 15:20:26 +00:00
committed by Gitee
15 changed files with 521 additions and 0 deletions
@@ -0,0 +1,47 @@
# 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("//ark/js_runtime/js_runtime_config.gni")
import("//ark/js_runtime/test/test_helper.gni")
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
##################################fuzztest#####################################
ohos_fuzztest("test_ark_DispatchProtocolMessage_fuzzer") {
module_out_path = "ark/js_runtime"
sources = [ "ark_DispatchProtocolMessage_fuzzer.cpp" ]
configs = [
"//ark/js_runtime:ecma_test_config",
"//ark/js_runtime:ark_jsruntime_public_config",
"//ark/js_runtime:ark_jsruntime_config",
"$ark_root/runtime:arkruntime_public_config",
]
deps = [
"$ark_root/libpandabase:libarkbase",
"$ark_root/runtime:libarkruntime",
"//ark/js_runtime:libark_jsruntime",
"//ark/js_runtime/ecmascript/tooling:libark_ecma_debugger_static",
sdk_libc_secshared_dep,
]
}
group("fuzztest") {
testonly = true
deps = []
deps += [ ":test_ark_DispatchProtocolMessage_fuzzer" ]
}
@@ -0,0 +1,38 @@
/*
* 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 "ark_DispatchProtocolMessage_fuzzer.h"
#include<cstddef>
#include<cstdint>
#include "ecmascript/tooling/debugger_service.h"
using namespace panda::tooling::ecmascript;
namespace OHOS {
bool doSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
std::string message(data, data+size);
panda::tooling::ecmascript::DispatchProtocolMessage(message);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
// Run your code on data.
OHOS::doSomethingInterestingWithMyAPI(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 ARK_DISPATCHPROTOCOLMESSAGE_FUZZER_H
#define ARK_DISPATCHPROTOCOLMESSAGE_FUZZER_H
#define FUZZ_PROJECT_NAME "ark_DispatchProtocolMessage_fuzzer"
#endif
@@ -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,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>
+48
View File
@@ -0,0 +1,48 @@
# 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("//ark/js_runtime/js_runtime_config.gni")
import("//ark/js_runtime/test/test_helper.gni")
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
############################fuzztest################################
ohos_fuzztest("test_ark_Execute_fuzzer") {
module_out_path = "ark/js_runtime"
sources = [ "ark_Execute_fuzzer.cpp" ]
configs = [
"//ark/js_runtime:ecma_test_config",
"//ark/js_runtime:ark_jsruntime_public_config",
"//ark/js_runtime:ark_jsruntime_config",
"$ark_root/runtime:arkruntime_public_config",
]
deps = [
"$ark_root/libpandabase:libarkbase",
"$ark_root/runtime:libarkruntime",
"//ark/js_runtime:libark_js_intl_static",
"//ark/js_runtime:libark_jsruntime",
"//ark/js_runtime:libark_jsruntime_static",
sdk_libc_secshared_dep,
]
}
group("fuzztest") {
testonly = true
deps = []
deps += [ ":test_ark_Execute_fuzzer" ]
}
@@ -0,0 +1,52 @@
/*
* 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 "ark_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 doSomethingInterestingWithMyAPI(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);
std::string a = entry->StringRef::ToString();
JSNApi::Execute(jsvm, data, size, a);
JSNApi::DestroyJSVM(jsvm);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
// Run your code on data.
OHOS::doSomethingInterestingWithMyAPI(data, size);
return 0;
}
@@ -0,0 +1,48 @@
/*
* 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 ARK_EXECUTE_FUZZER_H
#define ARK_EXECUTE_FUZZER_H
#include <cstdint>
#include <unistd.h>
#include <cstdlib>
#include <fcntl.h>
int makeUniqFile(const uint8_t *data, size_t size, char* file_name_uniq, const char* ext)
{
int UNIQ_ID = 0;
int fd = open(file_name_uniq, O_CREAT | O_RDWR, 0666);
if (fd == -1) {
return -1;
}
write(fd, data, size);
close(fd);
UNIQ_ID++;
return 0;
}
uint16_t U16_AT(const uint8_t *ptr)
{
return ((ptr[0] << 8) | ptr[1]);
}
uint32_t U32_AT(const uint8_t *ptr)
{
return ((ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]);
}
#endif
@@ -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,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>
@@ -0,0 +1,47 @@
# 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("//ark/js_runtime/js_runtime_config.gni")
import("//ark/js_runtime/test/test_helper.gni")
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
####################################fuzztest##################################
ohos_fuzztest("test_ark_InitializeDebugger_fuzzer") {
module_out_path = "ark/js_runtime"
sources = [ "ark_InitializeDebugger_fuzzer.cpp" ]
configs = [
"//ark/js_runtime:ecma_test_config",
"//ark/js_runtime:ark_jsruntime_public_config",
"//ark/js_runtime:ark_jsruntime_config",
"$ark_root/runtime:arkruntime_public_config",
]
deps = [
"$ark_root/libpandabase:libarkbase",
"$ark_root/runtime:libarkruntime",
"//ark/js_runtime:libark_jsruntime",
"//ark/js_runtime/ecmascript/tooling:libark_ecma_debugger_static",
sdk_libc_secshared_dep,
]
}
group("fuzztest") {
testonly = true
deps = []
deps += [ ":test_ark_InitializeDebugger_fuzzer" ]
}
@@ -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 "ark_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::tooling::ecmascript;
bool createstatus = true;
namespace OHOS {
bool doSomethingInterestingWithMyAPI(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 onResponse = [data, size](std::string) {
return;
};
panda::tooling::ecmascript::InitializeDebugger(onResponse, jsvm);
panda::tooling::ecmascript::UninitializeDebugger();
JSNApi::DestroyJSVM(jsvm);
return true;
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
// Run your code on data.
OHOS::doSomethingInterestingWithMyAPI(data, size);
return 0;
}
@@ -0,0 +1,48 @@
/*
* 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 ARK_INITIALIZEDEBUGGER_FUZZER_H
#define ARK_INITIALIZEDEBUGGER_FUZZER_H
#include <cstdint>
#include <unistd.h>
#include <cstdlib>
#include <fcntl.h>
int makeUniqFile(const uint8_t *data, size_t size, char* file_name_uniq, const char* ext)
{
int UNIQ_ID = 0;
int fd = open(file_name_uniq, O_CREAT | O_RDWR, 0666);
if (fd == -1) {
return -1;
}
write(fd, data, size);
close(fd);
UNIQ_ID++;
return 0;
}
uint16_t U16_AT(const uint8_t *ptr)
{
return ((ptr[0] << 8) | ptr[1]);
}
uint32_t U32_AT(const uint8_t *ptr)
{
return ((ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3]);
}
#endif
@@ -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,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>