diff --git a/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/BUILD.gn b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/BUILD.gn new file mode 100644 index 00000000..7a9f8372 --- /dev/null +++ b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/BUILD.gn @@ -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" ] +} diff --git a/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/ark_DispatchProtocolMessage_fuzzer.cpp b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/ark_DispatchProtocolMessage_fuzzer.cpp new file mode 100644 index 00000000..008a2f86 --- /dev/null +++ b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/ark_DispatchProtocolMessage_fuzzer.cpp @@ -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 +#include +#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; +} \ No newline at end of file diff --git a/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/ark_DispatchProtocolMessage_fuzzer.h b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/ark_DispatchProtocolMessage_fuzzer.h new file mode 100644 index 00000000..c8ebdc99 --- /dev/null +++ b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/ark_DispatchProtocolMessage_fuzzer.h @@ -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 \ No newline at end of file diff --git a/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/corpus/init b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/corpus/init new file mode 100644 index 00000000..b9a20c8e --- /dev/null +++ b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/project.yaml b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/project.yaml new file mode 100644 index 00000000..afd90798 --- /dev/null +++ b/test/fuzztest/ark_DispatchProtocolMessage_fuzzer/project.yaml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/ark_Execute_fuzzer/BUILD.gn b/test/fuzztest/ark_Execute_fuzzer/BUILD.gn new file mode 100644 index 00000000..5643fb50 --- /dev/null +++ b/test/fuzztest/ark_Execute_fuzzer/BUILD.gn @@ -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" ] +} diff --git a/test/fuzztest/ark_Execute_fuzzer/ark_Execute_fuzzer.cpp b/test/fuzztest/ark_Execute_fuzzer/ark_Execute_fuzzer.cpp new file mode 100644 index 00000000..8c25dd2e --- /dev/null +++ b/test/fuzztest/ark_Execute_fuzzer/ark_Execute_fuzzer.cpp @@ -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 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; +} \ No newline at end of file diff --git a/test/fuzztest/ark_Execute_fuzzer/ark_Execute_fuzzer.h b/test/fuzztest/ark_Execute_fuzzer/ark_Execute_fuzzer.h new file mode 100644 index 00000000..8ec3df32 --- /dev/null +++ b/test/fuzztest/ark_Execute_fuzzer/ark_Execute_fuzzer.h @@ -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 +#include +#include +#include + +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 \ No newline at end of file diff --git a/test/fuzztest/ark_Execute_fuzzer/corpus/init b/test/fuzztest/ark_Execute_fuzzer/corpus/init new file mode 100644 index 00000000..b9a20c8e --- /dev/null +++ b/test/fuzztest/ark_Execute_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/ark_Execute_fuzzer/project.yaml b/test/fuzztest/ark_Execute_fuzzer/project.yaml new file mode 100644 index 00000000..1020c7b4 --- /dev/null +++ b/test/fuzztest/ark_Execute_fuzzer/project.yaml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ark_InitializeDebugger_fuzzer/BUILD.gn b/test/fuzztest/ark_InitializeDebugger_fuzzer/BUILD.gn new file mode 100644 index 00000000..e3bce040 --- /dev/null +++ b/test/fuzztest/ark_InitializeDebugger_fuzzer/BUILD.gn @@ -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" ] +} diff --git a/test/fuzztest/ark_InitializeDebugger_fuzzer/ark_InitializeDebugger_fuzzer.cpp b/test/fuzztest/ark_InitializeDebugger_fuzzer/ark_InitializeDebugger_fuzzer.cpp new file mode 100644 index 00000000..2dd85466 --- /dev/null +++ b/test/fuzztest/ark_InitializeDebugger_fuzzer/ark_InitializeDebugger_fuzzer.cpp @@ -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 +#include +#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; +} \ No newline at end of file diff --git a/test/fuzztest/ark_InitializeDebugger_fuzzer/ark_InitializeDebugger_fuzzer.h b/test/fuzztest/ark_InitializeDebugger_fuzzer/ark_InitializeDebugger_fuzzer.h new file mode 100644 index 00000000..c9fc3b01 --- /dev/null +++ b/test/fuzztest/ark_InitializeDebugger_fuzzer/ark_InitializeDebugger_fuzzer.h @@ -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 +#include +#include +#include + +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 \ No newline at end of file diff --git a/test/fuzztest/ark_InitializeDebugger_fuzzer/corpus/init b/test/fuzztest/ark_InitializeDebugger_fuzzer/corpus/init new file mode 100644 index 00000000..b9a20c8e --- /dev/null +++ b/test/fuzztest/ark_InitializeDebugger_fuzzer/corpus/init @@ -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 \ No newline at end of file diff --git a/test/fuzztest/ark_InitializeDebugger_fuzzer/project.yaml b/test/fuzztest/ark_InitializeDebugger_fuzzer/project.yaml new file mode 100644 index 00000000..1020c7b4 --- /dev/null +++ b/test/fuzztest/ark_InitializeDebugger_fuzzer/project.yaml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +