新增fuzz测试用例

Signed-off-by: xiekaiming <xiekaiming2@huawei.com>
This commit is contained in:
xiekaiming
2023-11-25 17:08:39 +08:00
parent 8f4319f1f5
commit 9cf5929fb5
21 changed files with 564 additions and 2 deletions
+2 -1
View File
@@ -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"
]
}
}
+24
View File
@@ -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" ]
}
}
+22
View File
@@ -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",
]
}
+44
View File
@@ -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"
}
@@ -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
@@ -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 <cstddef>
#include <cstdint>
#include <string>
#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;
}
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -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"
}
@@ -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
@@ -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 <cstddef>
#include <cstdint>
#include <string>
#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;
}
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -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"
}
@@ -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
@@ -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 <cstddef>
#include <cstdint>
#include <string>
#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;
}
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -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"
}
@@ -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
@@ -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 <cstddef>
#include <cstdint>
#include <string>
#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;
}
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
+1 -1
View File
@@ -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"
}
}