diff --git a/bundle.json b/bundle.json index cee9e5162be15711632f2271459657f919034082..92295d957528a05b9aba8beb23f8341934ab050c 100644 --- a/bundle.json +++ b/bundle.json @@ -14,8 +14,8 @@ "en": "README" }, "component": { - "name": "thirdparty_musl", - "subsystem": "", + "name": "musl", + "subsystem": "thirdparty", "syscap": [], "features": [], "adapted_system_type": [], @@ -28,7 +28,9 @@ "build": { "sub_component": [], "inner_kits": [], - "test": [] + "test": [ + "//third_party/musl/fuzztest:fuzztest" + ] } } } \ No newline at end of file diff --git a/fuzztest/BUILD.gn b/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..586c20571981a4d0b715e6fbea431cf6ed1b70af --- /dev/null +++ b/fuzztest/BUILD.gn @@ -0,0 +1,20 @@ +# 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/test.gni") + +group("fuzztest") { + testonly = true + deps = [] + + deps += [ "atoi_fuzzer:fuzztest" ] +} diff --git a/fuzztest/atoi_fuzzer/BUILD.gn b/fuzztest/atoi_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..be93ae335d0558ec1909e076d4cd174f3facf943 --- /dev/null +++ b/fuzztest/atoi_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +module_output_path = "musl/services" + +##############################fuzztest########################################## +ohos_fuzztest("AtoiFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//third_party/musl/fuzztest/atoi_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "atoi_fuzzer.cpp" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AtoiFuzzTest", + ] +} +############################################################################### diff --git a/fuzztest/atoi_fuzzer/atoi_fuzzer.cpp b/fuzztest/atoi_fuzzer/atoi_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca51d8c0b9b0ee03ca4d6b46f05d024b4827fab3 --- /dev/null +++ b/fuzztest/atoi_fuzzer/atoi_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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. + */ + +#include "atoi_fuzzer.h" + +#include +#include +#include +#include +#include + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + const char *s = (char*)data; + return atoi(s); + } +} + +/* 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; +} + diff --git a/fuzztest/atoi_fuzzer/atoi_fuzzer.h b/fuzztest/atoi_fuzzer/atoi_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0c46f5c3d14e9ef57616a071add401ade90faba7 --- /dev/null +++ b/fuzztest/atoi_fuzzer/atoi_fuzzer.h @@ -0,0 +1,24 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include + +#define FUZZ_PROJECT_NAME "atoi_fuzzer" + diff --git a/fuzztest/atoi_fuzzer/corpus/init b/fuzztest/atoi_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..351b32f2a5b564aef11b90052ca830d1ca803bf3 --- /dev/null +++ b/fuzztest/atoi_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/fuzztest/atoi_fuzzer/project.xml b/fuzztest/atoi_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e --- /dev/null +++ b/fuzztest/atoi_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +