From 9cf5929fb5bf966089d15efc9162953691a5c4f5 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Sat, 25 Nov 2023 17:08:39 +0800 Subject: [PATCH] =?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