From 35c00287326dd83584ec09cdefd56565749beed8 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Sat, 25 Nov 2023 17:08:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9Efuzz=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- bundle.json | 3 +- common/config/BUILD.gn | 24 ++++++++++ test/fuzztest/BUILD.gn | 22 +++++++++ test/fuzztest/getcfgfiles_fuzzer/BUILD.gn | 44 +++++++++++++++++ test/fuzztest/getcfgfiles_fuzzer/corpus/init | 14 ++++++ .../getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp | 45 ++++++++++++++++++ test/fuzztest/getcfgfiles_fuzzer/project.xml | 25 ++++++++++ test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn | 44 +++++++++++++++++ .../fuzztest/getcfgfilesex_fuzzer/corpus/init | 14 ++++++ .../getcfgfilesex_fuzzer.cpp | 47 +++++++++++++++++++ .../fuzztest/getcfgfilesex_fuzzer/project.xml | 25 ++++++++++ test/fuzztest/getonecfgfile_fuzzer/BUILD.gn | 44 +++++++++++++++++ .../fuzztest/getonecfgfile_fuzzer/corpus/init | 14 ++++++ .../getonecfgfile_fuzzer.cpp | 44 +++++++++++++++++ .../fuzztest/getonecfgfile_fuzzer/project.xml | 25 ++++++++++ test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn | 44 +++++++++++++++++ .../getonecfgfileex_fuzzer/corpus/init | 14 ++++++ .../getonecfgfileex_fuzzer.cpp | 47 +++++++++++++++++++ .../getonecfgfileex_fuzzer/project.xml | 25 ++++++++++ test/unittest/BUILD.gn | 2 +- test/{ => unittest}/resource/ohos_test.xml | 0 21 files changed, 564 insertions(+), 2 deletions(-) create mode 100644 common/config/BUILD.gn create mode 100644 test/fuzztest/BUILD.gn create mode 100644 test/fuzztest/getcfgfiles_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getcfgfiles_fuzzer/corpus/init create mode 100644 test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp create mode 100644 test/fuzztest/getcfgfiles_fuzzer/project.xml create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/corpus/init create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp create mode 100644 test/fuzztest/getcfgfilesex_fuzzer/project.xml create mode 100644 test/fuzztest/getonecfgfile_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getonecfgfile_fuzzer/corpus/init create mode 100644 test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp create mode 100644 test/fuzztest/getonecfgfile_fuzzer/project.xml create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/corpus/init create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp create mode 100644 test/fuzztest/getonecfgfileex_fuzzer/project.xml rename test/{ => unittest}/resource/ohos_test.xml (100%) diff --git a/bundle.json b/bundle.json index f37affa..cf2c993 100644 --- a/bundle.json +++ b/bundle.json @@ -47,7 +47,8 @@ } ], "test": [ - "//base/customization/config_policy/test/unittest:ConfigPolicyUtilsTest" + "//base/customization/config_policy/test/unittest:ConfigPolicyUtilsTest", + "//base/customization/config_policy/test/fuzztest:fuzztest" ] } } diff --git a/common/config/BUILD.gn b/common/config/BUILD.gn new file mode 100644 index 0000000..b8f1b88 --- /dev/null +++ b/common/config/BUILD.gn @@ -0,0 +1,24 @@ +# 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. + +declare_args() { + config_policy_feature_coverage = false +} + +config("coverage_flags") { + if (config_policy_feature_coverage) { + cflags = [ "--coverage" ] + cflags_cc = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn new file mode 100644 index 0000000..f47317e --- /dev/null +++ b/test/fuzztest/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2023 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. + +group("fuzztest") { + testonly = true + deps = [ + "getonecfgfile_fuzzer:GetOneCfgFileFuzzTest", + "getonecfgfileex_fuzzer:GetOneCfgFileExFuzzTest", + "getcfgfiles_fuzzer:GetCfgFilesFuzzTest", + "getcfgfilesex_fuzzer:GetCfgFilesExFuzzTest", + ] +} diff --git a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn new file mode 100644 index 0000000..680cd36 --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 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/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetCfgFilesFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getcfgfiles_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getcfgfiles_fuzzer/corpus/init b/test/fuzztest/getcfgfiles_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp new file mode 100644 index 0000000..89e024f --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023 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 "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getcfgfiles_fuzzer" + + +namespace OHOS { + bool fuzzGetCfgFiles(const uint8_t* data, size_t size) + { + std::string cfgPath((const char*) data, size); + CfgFiles *cfgFiles = GetCfgFiles(cfgPath.c_str()); + bool result = cfgFiles != nullptr; + FreeCfgFiles(cfgFiles); + return result; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetCfgFiles(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getcfgfiles_fuzzer/project.xml b/test/fuzztest/getcfgfiles_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getcfgfiles_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn new file mode 100644 index 0000000..a51cc64 --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 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/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetCfgFilesExFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getcfgfilesex_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getcfgfilesex_fuzzer/corpus/init b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp new file mode 100644 index 0000000..36cf6ea --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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 "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getcfgfilesex_fuzzer" + + +namespace OHOS { + bool fuzzGetCfgFilesEx(const uint8_t* data, size_t size) + { + std::string cfgPath((const char*) data, size / 2); + std::string extra((const char*) data + size / 2, size / 2); + int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; + CfgFiles *cfgFiles = GetCfgFilesEx(cfgPath.c_str(), followMode, extra.c_str()); + bool result = cfgFiles != nullptr; + FreeCfgFiles(cfgFiles); + return result; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetCfgFilesEx(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getcfgfilesex_fuzzer/project.xml b/test/fuzztest/getcfgfilesex_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getcfgfilesex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn new file mode 100644 index 0000000..3eca152 --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 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/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetOneCfgFileFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getonecfgfile_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getonecfgfile_fuzzer/corpus/init b/test/fuzztest/getonecfgfile_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp new file mode 100644 index 0000000..d5c974f --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 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 "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getonecfgfile_fuzzer" + + +namespace OHOS { + bool fuzzGetOneCfgFile(const uint8_t* data, size_t size) + { + std::string userPath((const char*) data, size); + char buf[MAX_PATH_LEN] = {0}; + char *filePath = GetOneCfgFile(userPath.c_str(), buf, MAX_PATH_LEN); + return filePath != nullptr; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetOneCfgFile(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getonecfgfile_fuzzer/project.xml b/test/fuzztest/getonecfgfile_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getonecfgfile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn new file mode 100644 index 0000000..0b1d0e3 --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 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/ohos.gni") +import("//build/test.gni") +module_output_path = "customization/config_policy" + +##############################fuzztest########################################## +ohos_fuzztest("GetOneCfgFileExFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "." + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + include_dirs = [ "../../../interfaces/inner_api/include" ] + configs = [ "../../../common/config:coverage_flags" ] + sources = [ "getonecfgfileex_fuzzer.cpp" ] + + deps = [ "../../../frameworks/config_policy:configpolicy_util" ] + + external_deps = [ + "c_utils:utils" + ] + + subsystem_name = "customization" + part_name = "config_policy" +} diff --git a/test/fuzztest/getonecfgfileex_fuzzer/corpus/init b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp new file mode 100644 index 0000000..ba5839e --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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 "config_policy_utils.h" + +#define FUZZ_PROJECT_NAME "getonecfgfileex_fuzzer" + +constexpr size_t MIN_SIZE = 4; + +namespace OHOS { + bool fuzzGetOneCfgFileEx(const uint8_t* data, size_t size) + { + std::string userPath((const char*) data, size / 2); + std::string extra((const char*) data + size / 2, size / 2); + int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; + char buf[MAX_PATH_LEN] = {0}; + char *filePath = GetOneCfgFileEx(userPath.c_str(), buf, MAX_PATH_LEN, followMode, extra.c_str()); + return filePath != nullptr; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < MIN_SIZE) { + return 0; + } + // Run your code on data. + OHOS::fuzzGetOneCfgFileEx(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/getonecfgfileex_fuzzer/project.xml b/test/fuzztest/getonecfgfileex_fuzzer/project.xml new file mode 100644 index 0000000..4fdbc40 --- /dev/null +++ b/test/fuzztest/getonecfgfileex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index fc2f408..10642ea 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -44,6 +44,6 @@ if (defined(ohos_lite)) { include_dirs = config_policy_include_dirs deps = config_policy_deps external_deps = [ "init:libbegetutil" ] - resource_config_file = "../resource/ohos_test.xml" + resource_config_file = "./resource/ohos_test.xml" } } diff --git a/test/resource/ohos_test.xml b/test/unittest/resource/ohos_test.xml similarity index 100% rename from test/resource/ohos_test.xml rename to test/unittest/resource/ohos_test.xml -- Gitee From 6b79c9d9ababe062e317342cd8240b1b8ae8f36c Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 27 Nov 2023 18:49:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?FUZZ=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/BUILD.gn | 4 ++-- test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp | 4 ++-- .../getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp | 9 +++++---- .../getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp | 4 ++-- .../getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp | 6 +++--- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index f47317e..76cc189 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -14,9 +14,9 @@ group("fuzztest") { testonly = true deps = [ - "getonecfgfile_fuzzer:GetOneCfgFileFuzzTest", - "getonecfgfileex_fuzzer:GetOneCfgFileExFuzzTest", "getcfgfiles_fuzzer:GetCfgFilesFuzzTest", "getcfgfilesex_fuzzer:GetCfgFilesExFuzzTest", + "getonecfgfile_fuzzer:GetOneCfgFileFuzzTest", + "getonecfgfileex_fuzzer:GetOneCfgFileExFuzzTest", ] } diff --git a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp index 89e024f..3d7f621 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp +++ b/test/fuzztest/getcfgfiles_fuzzer/getcfgfiles_fuzzer.cpp @@ -23,7 +23,7 @@ namespace OHOS { - bool fuzzGetCfgFiles(const uint8_t* data, size_t size) + bool FuzzGetCfgFiles(const uint8_t* data, size_t size) { std::string cfgPath((const char*) data, size); CfgFiles *cfgFiles = GetCfgFiles(cfgPath.c_str()); @@ -40,6 +40,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } // Run your code on data. - OHOS::fuzzGetCfgFiles(data, size); + OHOS::FuzzGetCfgFiles(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp index 36cf6ea..7679a21 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp +++ b/test/fuzztest/getcfgfilesex_fuzzer/getcfgfilesex_fuzzer.cpp @@ -21,12 +21,13 @@ #define FUZZ_PROJECT_NAME "getcfgfilesex_fuzzer" +constexpr size_t MIN_SIZE = 4; namespace OHOS { - bool fuzzGetCfgFilesEx(const uint8_t* data, size_t size) + bool FuzzGetCfgFilesEx(const uint8_t* data, size_t size) { std::string cfgPath((const char*) data, size / 2); - std::string extra((const char*) data + size / 2, size / 2); + std::string extra((const char*) data + size / 2, size - size / 2); int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; CfgFiles *cfgFiles = GetCfgFilesEx(cfgPath.c_str(), followMode, extra.c_str()); bool result = cfgFiles != nullptr; @@ -38,10 +39,10 @@ namespace OHOS { // Fuzzer entry point. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - if (data == nullptr) { + if (data == nullptr || size < MIN_SIZE) { return 0; } // Run your code on data. - OHOS::fuzzGetCfgFilesEx(data, size); + OHOS::FuzzGetCfgFilesEx(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp index d5c974f..1d6d43f 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp +++ b/test/fuzztest/getonecfgfile_fuzzer/getonecfgfile_fuzzer.cpp @@ -23,7 +23,7 @@ namespace OHOS { - bool fuzzGetOneCfgFile(const uint8_t* data, size_t size) + bool FuzzGetOneCfgFile(const uint8_t* data, size_t size) { std::string userPath((const char*) data, size); char buf[MAX_PATH_LEN] = {0}; @@ -39,6 +39,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } // Run your code on data. - OHOS::fuzzGetOneCfgFile(data, size); + OHOS::FuzzGetOneCfgFile(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp index ba5839e..5224a37 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp +++ b/test/fuzztest/getonecfgfileex_fuzzer/getonecfgfileex_fuzzer.cpp @@ -24,10 +24,10 @@ constexpr size_t MIN_SIZE = 4; namespace OHOS { - bool fuzzGetOneCfgFileEx(const uint8_t* data, size_t size) + bool FuzzGetOneCfgFileEx(const uint8_t* data, size_t size) { std::string userPath((const char*) data, size / 2); - std::string extra((const char*) data + size / 2, size / 2); + std::string extra((const char*) data + size / 2, size - size / 2); int followMode = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; char buf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFileEx(userPath.c_str(), buf, MAX_PATH_LEN, followMode, extra.c_str()); @@ -42,6 +42,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) return 0; } // Run your code on data. - OHOS::fuzzGetOneCfgFileEx(data, size); + OHOS::FuzzGetOneCfgFileEx(data, size); return 0; } \ No newline at end of file -- Gitee From 0e6b07b67852f3c6a79f24f60b38d64d42e2818d Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Mon, 27 Nov 2023 19:45:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?FUZZ=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/getcfgfiles_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getcfgfiles_fuzzer/corpus/init | 2 +- test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getcfgfilesex_fuzzer/corpus/init | 2 +- test/fuzztest/getonecfgfile_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getonecfgfile_fuzzer/corpus/init | 2 +- test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn | 4 +--- test/fuzztest/getonecfgfileex_fuzzer/corpus/init | 2 +- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn index 680cd36..913b590 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetCfgFilesFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getcfgfiles_fuzzer/corpus/init b/test/fuzztest/getcfgfiles_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/corpus/init +++ b/test/fuzztest/getcfgfiles_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 diff --git a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn index a51cc64..d1d041a 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetCfgFilesExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getcfgfilesex_fuzzer/corpus/init b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/corpus/init +++ b/test/fuzztest/getcfgfilesex_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 diff --git a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn index 3eca152..7c3b188 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetOneCfgFileFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfile_fuzzer/corpus/init b/test/fuzztest/getonecfgfile_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/corpus/init +++ b/test/fuzztest/getonecfgfile_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 diff --git a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn index 0b1d0e3..33dd1eb 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn @@ -35,9 +35,7 @@ ohos_fuzztest("GetOneCfgFileExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ - "c_utils:utils" - ] + external_deps = [ ] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfileex_fuzzer/corpus/init b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init index bc977bd..e4ceac1 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/corpus/init +++ b/test/fuzztest/getonecfgfileex_fuzzer/corpus/init @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2023 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 -- Gitee From 768cd9ac66e7a8a21de96d98d3c0382a61158cbe Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Tue, 28 Nov 2023 09:17:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?FUZZ=E8=A7=84=E8=8C=83=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- test/fuzztest/getcfgfiles_fuzzer/BUILD.gn | 2 +- test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn | 2 +- test/fuzztest/getonecfgfile_fuzzer/BUILD.gn | 2 +- test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn index 913b590..8ba4aa4 100644 --- a/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfiles_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetCfgFilesFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn index d1d041a..abe72f3 100644 --- a/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn +++ b/test/fuzztest/getcfgfilesex_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetCfgFilesExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn index 7c3b188..0582d5f 100644 --- a/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfile_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetOneCfgFileFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" diff --git a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn index 33dd1eb..df69bd4 100644 --- a/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn +++ b/test/fuzztest/getonecfgfileex_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("GetOneCfgFileExFuzzTest") { deps = [ "../../../frameworks/config_policy:configpolicy_util" ] - external_deps = [ ] + external_deps = [] subsystem_name = "customization" part_name = "config_policy" -- Gitee