diff --git a/tests/fuzztest/BUILD.gn b/tests/fuzztest/BUILD.gn index bbfb8cb..ba326cb 100644 --- a/tests/fuzztest/BUILD.gn +++ b/tests/fuzztest/BUILD.gn @@ -16,8 +16,17 @@ group("fuzztest") { deps = [] deps += [ + "annotationdataaccessor_fuzzer:fuzztest", + "begintracepoint_fuzzer:fuzztest", "checkheader_fuzzer:fuzztest", + "classdataaccessor_fuzzer:fuzztest", + "codedataaccessor_fuzzer:fuzztest", + "debuginfodataaccessor_fuzzer:fuzztest", + "fielddataaccessor_fuzzer:fuzztest", + "int64tracepoint_fuzzer:fuzztest", + "inttracepoint_fuzzer:fuzztest", "literaldataaccessor_fuzzer:fuzztest", + "load_fuzzer:fuzztest", "methoddataaccessor_fuzzer:fuzztest", "open_fuzzer:fuzztest", "openfrommemory1arg_fuzzer:fuzztest", @@ -26,5 +35,6 @@ group("fuzztest") { "openpandafilefrommemory_fuzzer:fuzztest", "openpandafileorzip_fuzzer:fuzztest", "openuncompressedarchive_fuzzer:fuzztest", + "resolvesymbol_fuzzer:fuzztest", ] } diff --git a/tests/fuzztest/annotationdataaccessor_fuzzer/BUILD.gn b/tests/fuzztest/annotationdataaccessor_fuzzer/BUILD.gn new file mode 100644 index 0000000..b6d9f1b --- /dev/null +++ b/tests/fuzztest/annotationdataaccessor_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("AnnotationDataAccessorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//ark/runtime_core/tests/fuzztest/annotationdataaccessor_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "annotationdataaccessor_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AnnotationDataAccessorFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/annotationdataaccessor_fuzzer/annotationdataaccessor_fuzzer.cpp b/tests/fuzztest/annotationdataaccessor_fuzzer/annotationdataaccessor_fuzzer.cpp new file mode 100644 index 0000000..6308d7f --- /dev/null +++ b/tests/fuzztest/annotationdataaccessor_fuzzer/annotationdataaccessor_fuzzer.cpp @@ -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 "annotationdataaccessor_fuzzer.h" + +#include "libpandafile/file.h" +#include "libpandafile/annotation_data_accessor.h" +#include "libpandafile/class_data_accessor-inl.h" + +namespace OHOS { + void AnnotationDataAccessorFuzzTest(const uint8_t* data, size_t size) + { + auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size); + if (pf == nullptr) { + return; + } + auto classes = pf->GetClasses(); + const auto &panda_file = *pf; + for (size_t i = 0; i < classes.Size(); i++) { + panda::panda_file::File::EntityId id(classes[i]); + if (panda_file.IsExternal(id)) { + continue; + } + + panda::panda_file::ClassDataAccessor cda(panda_file, id); + cda.EnumerateAnnotations([&](panda::panda_file::File::EntityId id) { + panda::panda_file::AnnotationDataAccessor ada(panda_file, id); + }); + } + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::AnnotationDataAccessorFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/annotationdataaccessor_fuzzer/annotationdataaccessor_fuzzer.h b/tests/fuzztest/annotationdataaccessor_fuzzer/annotationdataaccessor_fuzzer.h new file mode 100644 index 0000000..b477507 --- /dev/null +++ b/tests/fuzztest/annotationdataaccessor_fuzzer/annotationdataaccessor_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 ANNOTATIONDATAACCESSOR_FUZZER_H_ +#define ANNOTATIONDATAACCESSOR_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "annotationdataaccessor_fuzzer" + +#endif // ANNOTATIONDATAACCESSOR_FUZZER_H_ diff --git a/tests/fuzztest/annotationdataaccessor_fuzzer/corpus/init b/tests/fuzztest/annotationdataaccessor_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/annotationdataaccessor_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/annotationdataaccessor_fuzzer/project.xml b/tests/fuzztest/annotationdataaccessor_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/annotationdataaccessor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/begintracepoint_fuzzer/BUILD.gn b/tests/fuzztest/begintracepoint_fuzzer/BUILD.gn new file mode 100644 index 0000000..d93e614 --- /dev/null +++ b/tests/fuzztest/begintracepoint_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("BeginTracePointFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//ark/runtime_core/tests/fuzztest/begintracepoint_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "begintracepoint_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandabase:libarkbase_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":BeginTracePointFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/begintracepoint_fuzzer/begintracepoint_fuzzer.cpp b/tests/fuzztest/begintracepoint_fuzzer/begintracepoint_fuzzer.cpp new file mode 100644 index 0000000..e71e3d2 --- /dev/null +++ b/tests/fuzztest/begintracepoint_fuzzer/begintracepoint_fuzzer.cpp @@ -0,0 +1,34 @@ +/* + * 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 "begintracepoint_fuzzer.h" + +#include "trace/trace.h" + +namespace OHOS { + void BeginTracePointFuzzTest(const uint8_t* data, size_t size) + { + panda::trace::BeginTracePoint(std::string(data, data + size).c_str()); + panda::trace::EndTracePoint(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::BeginTracePointFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/begintracepoint_fuzzer/begintracepoint_fuzzer.h b/tests/fuzztest/begintracepoint_fuzzer/begintracepoint_fuzzer.h new file mode 100644 index 0000000..9109954 --- /dev/null +++ b/tests/fuzztest/begintracepoint_fuzzer/begintracepoint_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 BEGINTRACEPOINT_FUZZER_H_ +#define BEGINTRACEPOINT_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "begintracepoint_fuzzer" + +#endif // BEGINTRACEPOINT_FUZZER_H_ diff --git a/tests/fuzztest/begintracepoint_fuzzer/corpus/init b/tests/fuzztest/begintracepoint_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/begintracepoint_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/begintracepoint_fuzzer/project.xml b/tests/fuzztest/begintracepoint_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/begintracepoint_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/classdataaccessor_fuzzer/BUILD.gn b/tests/fuzztest/classdataaccessor_fuzzer/BUILD.gn new file mode 100644 index 0000000..8c14824 --- /dev/null +++ b/tests/fuzztest/classdataaccessor_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("ClassDataAccessorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//ark/runtime_core/tests/fuzztest/classdataaccessor_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "classdataaccessor_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ClassDataAccessorFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/classdataaccessor_fuzzer/classdataaccessor_fuzzer.cpp b/tests/fuzztest/classdataaccessor_fuzzer/classdataaccessor_fuzzer.cpp new file mode 100644 index 0000000..1812013 --- /dev/null +++ b/tests/fuzztest/classdataaccessor_fuzzer/classdataaccessor_fuzzer.cpp @@ -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. + */ + +#include "classdataaccessor_fuzzer.h" + +#include "libpandafile/file.h" +#include "libpandafile/class_data_accessor-inl.h" + +namespace OHOS { + void ClassDataAccessorFuzzTest(const uint8_t* data, size_t size) + { + auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size); + if (pf == nullptr) { + return; + } + auto classes = pf->GetClasses(); + const auto &panda_file = *pf; + for (size_t i = 0; i < classes.Size(); i++) { + panda::panda_file::File::EntityId id(classes[i]); + if (panda_file.IsExternal(id)) { + continue; + } + + panda::panda_file::ClassDataAccessor cda(panda_file, id); + } + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::ClassDataAccessorFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/classdataaccessor_fuzzer/classdataaccessor_fuzzer.h b/tests/fuzztest/classdataaccessor_fuzzer/classdataaccessor_fuzzer.h new file mode 100644 index 0000000..96b9168 --- /dev/null +++ b/tests/fuzztest/classdataaccessor_fuzzer/classdataaccessor_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 CLASSDATAACCESSOR_FUZZER_H_ +#define CLASSDATAACCESSOR_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "classdataaccessor_fuzzer" + +#endif // CLASSDATAACCESSOR_FUZZER_H_ diff --git a/tests/fuzztest/classdataaccessor_fuzzer/corpus/init b/tests/fuzztest/classdataaccessor_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/classdataaccessor_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/classdataaccessor_fuzzer/project.xml b/tests/fuzztest/classdataaccessor_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/classdataaccessor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/codedataaccessor_fuzzer/BUILD.gn b/tests/fuzztest/codedataaccessor_fuzzer/BUILD.gn new file mode 100644 index 0000000..058b980 --- /dev/null +++ b/tests/fuzztest/codedataaccessor_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("CodeDataAccessorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//ark/runtime_core/tests/fuzztest/codedataaccessor_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "codedataaccessor_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":CodeDataAccessorFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/codedataaccessor_fuzzer/codedataaccessor_fuzzer.cpp b/tests/fuzztest/codedataaccessor_fuzzer/codedataaccessor_fuzzer.cpp new file mode 100644 index 0000000..01a650b --- /dev/null +++ b/tests/fuzztest/codedataaccessor_fuzzer/codedataaccessor_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 "codedataaccessor_fuzzer.h" + +#include "libpandafile/file.h" +#include "libpandafile/class_data_accessor-inl.h" +#include "libpandafile/code_data_accessor-inl.h" +#include "libpandafile/method_data_accessor-inl.h" + +namespace OHOS { + void CodeDataAccessorFuzzTest(const uint8_t* data, size_t size) + { + auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size); + if (pf == nullptr) { + return; + } + auto classes = pf->GetClasses(); + const auto &panda_file = *pf; + for (size_t i = 0; i < classes.Size(); i++) { + panda::panda_file::File::EntityId id(classes[i]); + if (panda_file.IsExternal(id)) { + continue; + } + + panda::panda_file::ClassDataAccessor cda(panda_file, id); + cda.EnumerateMethods([&](panda::panda_file::MethodDataAccessor &data_accessor) { + panda::panda_file::CodeDataAccessor coda(panda_file, data_accessor.GetCodeId().value()); + }); + } + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::CodeDataAccessorFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/codedataaccessor_fuzzer/codedataaccessor_fuzzer.h b/tests/fuzztest/codedataaccessor_fuzzer/codedataaccessor_fuzzer.h new file mode 100644 index 0000000..d6428c5 --- /dev/null +++ b/tests/fuzztest/codedataaccessor_fuzzer/codedataaccessor_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 CODEDATAACCESSOR_FUZZER_H_ +#define CODEDATAACCESSOR_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "codedataaccessor_fuzzer" + +#endif // CODEDATAACCESSOR_FUZZER_H_ diff --git a/tests/fuzztest/codedataaccessor_fuzzer/corpus/init b/tests/fuzztest/codedataaccessor_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/codedataaccessor_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/codedataaccessor_fuzzer/project.xml b/tests/fuzztest/codedataaccessor_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/codedataaccessor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/debuginfodataaccessor_fuzzer/BUILD.gn b/tests/fuzztest/debuginfodataaccessor_fuzzer/BUILD.gn new file mode 100644 index 0000000..f38f6a8 --- /dev/null +++ b/tests/fuzztest/debuginfodataaccessor_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("DebugInfoDataAccessorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//ark/runtime_core/tests/fuzztest/debuginfodataaccessor_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "debuginfodataaccessor_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DebugInfoDataAccessorFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/debuginfodataaccessor_fuzzer/corpus/init b/tests/fuzztest/debuginfodataaccessor_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/debuginfodataaccessor_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/debuginfodataaccessor_fuzzer/debuginfodataaccessor_fuzzer.cpp b/tests/fuzztest/debuginfodataaccessor_fuzzer/debuginfodataaccessor_fuzzer.cpp new file mode 100644 index 0000000..b79a779 --- /dev/null +++ b/tests/fuzztest/debuginfodataaccessor_fuzzer/debuginfodataaccessor_fuzzer.cpp @@ -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 "debuginfodataaccessor_fuzzer.h" + +#include "libpandafile/class_data_accessor-inl.h" +#include "libpandafile/debug_data_accessor-inl.h" +#include "libpandafile/method_data_accessor-inl.h" + +namespace OHOS { + void DebugInfoDataAccessorFuzzTest(const uint8_t* data, size_t size) + { + auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size); + if (pf == nullptr) { + return; + } + auto classes = pf->GetClasses(); + const auto &panda_file = *pf; + for (size_t i = 0; i < classes.Size(); i++) { + panda::panda_file::File::EntityId id(classes[i]); + if (panda_file.IsExternal(id)) { + continue; + } + + panda::panda_file::ClassDataAccessor cda(panda_file, id); + cda.EnumerateMethods([&](panda::panda_file::MethodDataAccessor &data_accessor) { + panda::panda_file::DebugInfoDataAccessor dda(panda_file, data_accessor.GetDebugInfoId().value()); + }); + } + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DebugInfoDataAccessorFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/debuginfodataaccessor_fuzzer/debuginfodataaccessor_fuzzer.h b/tests/fuzztest/debuginfodataaccessor_fuzzer/debuginfodataaccessor_fuzzer.h new file mode 100644 index 0000000..5566ecf --- /dev/null +++ b/tests/fuzztest/debuginfodataaccessor_fuzzer/debuginfodataaccessor_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 DEBUGINFODATAACCESSOR_FUZZER_H_ +#define DEBUGINFODATAACCESSOR_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "debuginfodataaccessor_fuzzer" + +#endif // DEBUGINFODATAACCESSOR_FUZZER_H_ diff --git a/tests/fuzztest/debuginfodataaccessor_fuzzer/project.xml b/tests/fuzztest/debuginfodataaccessor_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/debuginfodataaccessor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/fielddataaccessor_fuzzer/BUILD.gn b/tests/fuzztest/fielddataaccessor_fuzzer/BUILD.gn new file mode 100644 index 0000000..4f6ade1 --- /dev/null +++ b/tests/fuzztest/fielddataaccessor_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("FieldDataAccessorFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//ark/runtime_core/tests/fuzztest/fielddataaccessor_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "fielddataaccessor_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandafile:libarkfile_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":FieldDataAccessorFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/fielddataaccessor_fuzzer/corpus/init b/tests/fuzztest/fielddataaccessor_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/fielddataaccessor_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/fielddataaccessor_fuzzer/fielddataaccessor_fuzzer.cpp b/tests/fuzztest/fielddataaccessor_fuzzer/fielddataaccessor_fuzzer.cpp new file mode 100644 index 0000000..c2858df --- /dev/null +++ b/tests/fuzztest/fielddataaccessor_fuzzer/fielddataaccessor_fuzzer.cpp @@ -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 "fielddataaccessor_fuzzer.h" + +#include "libpandafile/file.h" +#include "libpandafile/class_data_accessor-inl.h" +#include "libpandafile/field_data_accessor-inl.h" + +namespace OHOS { + void FieldDataAccessorFuzzTest(const uint8_t* data, size_t size) + { + auto pf = panda::panda_file::OpenPandaFileFromMemory(data, size); + if (pf == nullptr) { + return; + } + auto classes = pf->GetClasses(); + const auto &panda_file = *pf; + for (size_t i = 0; i < classes.Size(); i++) { + panda::panda_file::File::EntityId id(classes[i]); + if (panda_file.IsExternal(id)) { + continue; + } + + panda::panda_file::ClassDataAccessor cda(panda_file, id); + cda.EnumerateFields([&](panda::panda_file::FieldDataAccessor &data_accessor) { + return; + }); + } + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::FieldDataAccessorFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/fielddataaccessor_fuzzer/fielddataaccessor_fuzzer.h b/tests/fuzztest/fielddataaccessor_fuzzer/fielddataaccessor_fuzzer.h new file mode 100644 index 0000000..794b400 --- /dev/null +++ b/tests/fuzztest/fielddataaccessor_fuzzer/fielddataaccessor_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 FIELDDATAACCESSOR_FUZZER_H_ +#define FIELDDATAACCESSOR_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "fielddataaccessor_fuzzer" + +#endif // FIELDDATAACCESSOR_FUZZER_H_ diff --git a/tests/fuzztest/fielddataaccessor_fuzzer/project.xml b/tests/fuzztest/fielddataaccessor_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/fielddataaccessor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/int64tracepoint_fuzzer/BUILD.gn b/tests/fuzztest/int64tracepoint_fuzzer/BUILD.gn new file mode 100644 index 0000000..242c99a --- /dev/null +++ b/tests/fuzztest/int64tracepoint_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("Int64TracePointFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//ark/runtime_core/tests/fuzztest/int64tracepoint_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "int64tracepoint_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandabase:libarkbase_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":Int64TracePointFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/int64tracepoint_fuzzer/corpus/init b/tests/fuzztest/int64tracepoint_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/int64tracepoint_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/int64tracepoint_fuzzer/int64tracepoint_fuzzer.cpp b/tests/fuzztest/int64tracepoint_fuzzer/int64tracepoint_fuzzer.cpp new file mode 100644 index 0000000..a60fc65 --- /dev/null +++ b/tests/fuzztest/int64tracepoint_fuzzer/int64tracepoint_fuzzer.cpp @@ -0,0 +1,33 @@ +/* + * 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 "int64tracepoint_fuzzer.h" + +#include "trace/trace.h" + +namespace OHOS { + void Int64TracePointFuzzTest(const uint8_t* data, size_t size) + { + panda::trace::Int64TracePoint(std::string(data, data + size).c_str(), size); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::Int64TracePointFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/int64tracepoint_fuzzer/int64tracepoint_fuzzer.h b/tests/fuzztest/int64tracepoint_fuzzer/int64tracepoint_fuzzer.h new file mode 100644 index 0000000..5fe5ae1 --- /dev/null +++ b/tests/fuzztest/int64tracepoint_fuzzer/int64tracepoint_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 INT64TRACEPOINT_FUZZER_H_ +#define INT64TRACEPOINT_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "int64tracepoint_fuzzer" + +#endif // INT64TRACEPOINT_FUZZER_H_ diff --git a/tests/fuzztest/int64tracepoint_fuzzer/project.xml b/tests/fuzztest/int64tracepoint_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/int64tracepoint_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/inttracepoint_fuzzer/BUILD.gn b/tests/fuzztest/inttracepoint_fuzzer/BUILD.gn new file mode 100644 index 0000000..d525107 --- /dev/null +++ b/tests/fuzztest/inttracepoint_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("IntTracePointFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//ark/runtime_core/tests/fuzztest/inttracepoint_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "inttracepoint_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandabase:libarkbase_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":IntTracePointFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/inttracepoint_fuzzer/corpus/init b/tests/fuzztest/inttracepoint_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/inttracepoint_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/inttracepoint_fuzzer/inttracepoint_fuzzer.cpp b/tests/fuzztest/inttracepoint_fuzzer/inttracepoint_fuzzer.cpp new file mode 100644 index 0000000..3684526 --- /dev/null +++ b/tests/fuzztest/inttracepoint_fuzzer/inttracepoint_fuzzer.cpp @@ -0,0 +1,33 @@ +/* + * 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 "inttracepoint_fuzzer.h" + +#include "trace/trace.h" + +namespace OHOS { + void IntTracePointFuzzTest(const uint8_t* data, size_t size) + { + panda::trace::IntTracePoint(std::string(data, data + size).c_str(), size); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::IntTracePointFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/inttracepoint_fuzzer/inttracepoint_fuzzer.h b/tests/fuzztest/inttracepoint_fuzzer/inttracepoint_fuzzer.h new file mode 100644 index 0000000..1607c87 --- /dev/null +++ b/tests/fuzztest/inttracepoint_fuzzer/inttracepoint_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 INTTRACEPOINT_FUZZER_H_ +#define INTTRACEPOINT_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "inttracepoint_fuzzer" + +#endif // INTTRACEPOINT_FUZZER_H_ diff --git a/tests/fuzztest/inttracepoint_fuzzer/project.xml b/tests/fuzztest/inttracepoint_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/inttracepoint_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/load_fuzzer/BUILD.gn b/tests/fuzztest/load_fuzzer/BUILD.gn new file mode 100644 index 0000000..3335ee4 --- /dev/null +++ b/tests/fuzztest/load_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("LoadFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//ark/runtime_core/tests/fuzztest/load_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "load_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandabase:libarkbase_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":LoadFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/load_fuzzer/corpus/init b/tests/fuzztest/load_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/load_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/load_fuzzer/load_fuzzer.cpp b/tests/fuzztest/load_fuzzer/load_fuzzer.cpp new file mode 100644 index 0000000..705ba85 --- /dev/null +++ b/tests/fuzztest/load_fuzzer/load_fuzzer.cpp @@ -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. + */ + +#include "load_fuzzer.h" + +#include + +#include "os/library_loader.h" + +namespace OHOS { + void LoadFuzzTest(const uint8_t* data, size_t size) + { + /* Create data source */ + const char *name = "__LoadFuzzTest.tmp"; + FILE *fp = fopen(name, "wb"); + if (fp == nullptr) { + return; + } + (void)fwrite(data, sizeof(uint8_t), size, fp); + (void)fclose(fp); + + { + panda::os::library_loader::Load(name); + } + + (void)remove(name); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::LoadFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/load_fuzzer/load_fuzzer.h b/tests/fuzztest/load_fuzzer/load_fuzzer.h new file mode 100644 index 0000000..39612e7 --- /dev/null +++ b/tests/fuzztest/load_fuzzer/load_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 LOAD_FUZZER_H_ +#define LOAD_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "load_fuzzer" + +#endif // LOAD_FUZZER_H_ diff --git a/tests/fuzztest/load_fuzzer/project.xml b/tests/fuzztest/load_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/load_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/resolvesymbol_fuzzer/BUILD.gn b/tests/fuzztest/resolvesymbol_fuzzer/BUILD.gn new file mode 100644 index 0000000..af6851a --- /dev/null +++ b/tests/fuzztest/resolvesymbol_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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. + +import("//build/ohos.gni") + +#####################hydra-fuzz################### +import("//build/test.gni") +module_output_path = "ark/runtime_core" + +##############################fuzztest########################################## +ohos_fuzztest("ResolveSymbolFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//ark/runtime_core/tests/fuzztest/resolvesymbol_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "resolvesymbol_fuzzer.cpp" ] + deps = [ "//ark/runtime_core/libpandabase:libarkbase_static" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ResolveSymbolFuzzTest", + ] +} +############################################################################### diff --git a/tests/fuzztest/resolvesymbol_fuzzer/corpus/init b/tests/fuzztest/resolvesymbol_fuzzer/corpus/init new file mode 100644 index 0000000..8eb5a7d --- /dev/null +++ b/tests/fuzztest/resolvesymbol_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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 \ No newline at end of file diff --git a/tests/fuzztest/resolvesymbol_fuzzer/project.xml b/tests/fuzztest/resolvesymbol_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/tests/fuzztest/resolvesymbol_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/tests/fuzztest/resolvesymbol_fuzzer/resolvesymbol_fuzzer.cpp b/tests/fuzztest/resolvesymbol_fuzzer/resolvesymbol_fuzzer.cpp new file mode 100644 index 0000000..7202161 --- /dev/null +++ b/tests/fuzztest/resolvesymbol_fuzzer/resolvesymbol_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 "resolvesymbol_fuzzer.h" + +#include + +#include "os/library_loader.h" + +namespace OHOS { + void ResolveSymbolFuzzTest(const uint8_t* data, size_t size) + { + /* Create data source */ + const char *name = "__ResolveSymbolFuzzTest.tmp"; + FILE *fp = fopen(name, "wb"); + if (fp == nullptr) { + return; + } + (void)fwrite(data, sizeof(uint8_t), size, fp); + (void)fclose(fp); + + { + auto res = panda::os::library_loader::Load(name); + if (res) { + panda::os::library_loader::ResolveSymbol(*res, "StartDebug"); + panda::os::library_loader::ResolveSymbol(*res, "StopDebug"); + } + } + + (void)remove(name); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::ResolveSymbolFuzzTest(data, size); + return 0; +} diff --git a/tests/fuzztest/resolvesymbol_fuzzer/resolvesymbol_fuzzer.h b/tests/fuzztest/resolvesymbol_fuzzer/resolvesymbol_fuzzer.h new file mode 100644 index 0000000..c08f8d2 --- /dev/null +++ b/tests/fuzztest/resolvesymbol_fuzzer/resolvesymbol_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 RESOLVESYMBOL_FUZZER_H_ +#define RESOLVESYMBOL_FUZZER_H_ + +#define FUZZ_PROJECT_NAME "resolvesymbol_fuzzer" + +#endif // RESOLVESYMBOL_FUZZER_H_