init: add fuzztest code

Signed-off-by: xionglei6 <xionglei6@huawei.com>
This commit is contained in:
xionglei6 2021-12-01 15:19:01 +08:00
parent 235e009d56
commit 2809cfb095
40 changed files with 1724 additions and 0 deletions

535
test/fuzztest/BUILD.gn Normal file
View File

@ -0,0 +1,535 @@
# 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.
module_output_path = "startup/fuzztest"
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//build/ohos.gni")
ohos_static_library("libfuzz_utils") {
sources = [
"utils/fuzz_utils.cpp",
]
include_dirs = [ "//base/startup/init_lite/test/fuzztest/utils/include" ]
deps = []
part_name = "init"
}
##############################fuzztest##########################################
ohos_fuzztest("DoRebootFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
deps = [
"//base/startup/init_lite/interfaces/innerkits/reboot:libreboot_static",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"DoReboot_fuzzer/DoReboot_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("GetControlFileFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
deps = [
"//base/startup/init_lite/interfaces/innerkits/file:libfile",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"GetControlFile_fuzzer/GetControlFile_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("GetControlSocketFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
deps = [
"//base/startup/init_lite/interfaces/innerkits/socket:libsocket",
"//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"GetControlSocket_fuzzer/GetControlSocket_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("MountAllFstabFuzzTest") {
module_out_path = module_output_path
include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/test/fuzztest/utils/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits/fs_manager:libfsmanager_static",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//base/startup/init_lite/test/fuzztest:libfuzz_utils",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"MountAllFstab_fuzzer/MountAllFstab_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("ReadFileInDirFuzzTest") {
module_out_path = module_output_path
include_dirs = [
"//base/startup/init_lite/services/init/include",
"//base/startup/init_lite/services/include",
]
deps = [
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"ReadFileInDir_fuzzer/ReadFileInDir_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("StartDynamicProcessFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
deps = [
"//base/startup/init_lite/interfaces/innerkits/dynamic_service:dynamic_service",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"StartDynamicProcess_fuzzer/StartDynamicProcess_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("StopDynamicProcessFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
deps = [
"//base/startup/init_lite/interfaces/innerkits/dynamic_service:dynamic_service",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"StopDynamicProcess_fuzzer/StopDynamicProcess_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemDumpParametersFuzzTest") {
module_out_path = module_output_path
include_dirs = [
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/test/fuzztest/utils/include",
]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/test/fuzztest:libfuzz_utils",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemDumpParameters_fuzzer/SystemDumpParameters_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemFindParameterFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemFindParameter_fuzzer/SystemFindParameter_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemGetParameterFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemGetParameter_fuzzer/SystemGetParameter_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemGetParameterCommitIdFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemGetParameterCommitId_fuzzer/SystemGetParameterCommitId_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemGetParameterNameFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemGetParameterName_fuzzer/SystemGetParameterName_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemGetParameterValueFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemGetParameterValue_fuzzer/SystemGetParameterValue_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemSetParameterFuzztest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemSetParameter_fuzzer/SystemSetParameter_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemTraversalParameterFuzztest") {
module_out_path = module_output_path
include_dirs = [
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/init/include",
"//base/startup/init_lite/test/fuzztest/utils/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/test/fuzztest:libfuzz_utils",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemTraversalParameter_fuzzer/SystemTraversalParameter_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemWaitParameterFuzzTest") {
module_out_path = module_output_path
include_dirs = [ "//base/startup/init_lite/services/include/param" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemWaitParameter_fuzzer/SystemWaitParameter_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("SystemWatchParameterFuzzTest") {
module_out_path = module_output_path
include_dirs = [
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/init/include",
]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/param:param_watcheragent",
"//third_party/bounds_checking_function:libsec_static",
"//utils/native/base:utils",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_standard:samgr_proxy",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"SystemWatchParameter_fuzzer/SystemWatchParameter_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
ohos_fuzztest("UmountAllFstabFuzzTest") {
module_out_path = module_output_path
include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/test/fuzztest/utils/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits/fs_manager:libfsmanager_static",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//base/startup/init_lite/test/fuzztest:libfuzz_utils",
"//third_party/bounds_checking_function:libsec_static",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"UmountAllFstab_fuzzer/UmountAllFstab_fuzzer.cpp",
]
defines = [ "STARTUP_INIT_TEST" ]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DoRebootFuzzTest",
":GetControlFileFuzzTest",
":GetControlSocketFuzzTest",
":MountAllFstabFuzzTest",
":ReadFileInDirFuzzTest",
":StartDynamicProcessFuzzTest",
":StopDynamicProcessFuzzTest",
":SystemDumpParametersFuzzTest",
":SystemFindParameterFuzzTest",
":SystemGetParameterCommitIdFuzzTest",
":SystemGetParameterFuzzTest",
":SystemGetParameterNameFuzzTest",
":SystemGetParameterValueFuzzTest",
":SystemSetParameterFuzztest",
":SystemTraversalParameterFuzztest",
":SystemWaitParameterFuzzTest",
":SystemWatchParameterFuzzTest",
":UmountAllFstabFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,36 @@
/*
* 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 "DoReboot_fuzzer.h"
#include "init_reboot.h"
namespace OHOS {
bool FuzzDoReboot(const uint8_t* data, size_t size)
{
bool result = false;
if (!DoReboot(reinterpret_cast<const char*>(data))) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzDoReboot(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_DOREBOOT_FUZZER_H
#define TEST_FUZZTEST_DOREBOOT_FUZZER_H
#define FUZZ_PROJECT_NAME "DoReboot_fuzzer"
#endif

View File

@ -0,0 +1,36 @@
/*
* 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 "GetControlFile_fuzzer.h"
#include "init_file.h"
namespace OHOS {
bool FuzzGetControlFile(const uint8_t* data, size_t size)
{
bool result = false;
if (!GetControlFile(reinterpret_cast<const char*>(data))) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzGetControlFile(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_GETCONTROLFILE_FUZZER_H
#define TEST_FUZZTEST_GETCONTROLFILE_FUZZER_H
#define FUZZ_PROJECT_NAME "GetControlFile_fuzzer"
#endif

View File

@ -0,0 +1,36 @@
/*
* 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 "GetControlSocket_fuzzer.h"
#include "init_socket.h"
namespace OHOS {
bool FuzzGetControlSocket(const uint8_t* data, size_t size)
{
bool result = false;
if (!GetControlSocket(reinterpret_cast<const char*>(data))) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzGetControlSocket(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_GETCONTROLSOCKET_FUZZER_H
#define TEST_FUZZTEST_GETCONTROLSOCKET_FUZZER_H
#define FUZZ_PROJECT_NAME "GetControlSocket_fuzzer"
#endif

View File

@ -0,0 +1,52 @@
/*
* 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 "MountAllFstab_fuzzer.h"
#include <iostream>
#include "fs_manager/fs_manager.h"
#include "fuzz_utils.h"
namespace OHOS {
bool FuzzMountAllWithFstabFile(const uint8_t* data, size_t size)
{
bool result = false;
FILE *pFile = nullptr;
pFile = fopen("fstab.test", "w+");
if (pFile == nullptr) {
std::cout << "[fuzz] open file fstab.test failed";
return false;
}
if (reinterpret_cast<int>(fwrite(data, 1, size, pFile)) != size) {
std::cout << "[fuzz] write data to fstab.test failed";
fclose(pFile);
return false;
}
fclose(pFile);
CloseStdout();
if (!MountAllWithFstabFile("fstab.test", false)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzMountAllWithFstabFile(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_MOUNTALLFSTAB_FUZZER_H
#define TEST_FUZZTEST_MOUNTALLFSTAB_FUZZER_H
#define FUZZ_PROJECT_NAME "MountAllFstab_fuzzer"
#endif

View File

@ -0,0 +1,69 @@
/*
* 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 "ReadFileInDir_fuzzer.h"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "init.h"
#include "init_utils.h"
static int FakeParser(const char *testFile, void *context)
{
UNUSED(context);
std::ifstream fileStream;
fileStream.open(testFile);
std::vector<std::string> fileText;
std::string textLine;
while (getline(fileStream, textLine)) {
fileText.push_back(textLine);
}
fileStream.close();
std::vector<std::string>().swap(fileText);
return 0;
}
namespace OHOS {
bool FuzzReadFileInDir(const uint8_t* data, size_t size)
{
bool result = false;
FILE *pFile = nullptr;
pFile = fopen("ReadFileInDir.test", "w+");
if (pFile == nullptr) {
std::cout << "[fuzz] open file ReadFileInDir.test failed";
return false;
}
if (reinterpret_cast<int>(fwrite(data, 1, size, pFile)) != size) {
std::cout << "[fuzz] write data to ReadFileInDir.test failed";
fclose(pFile);
return false;
}
fclose(pFile);
if (!ReadFileInDir("/data", ".test", FakeParser, NULL)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzReadFileInDir(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_READFILEINDIR_FUZZER_H
#define TEST_FUZZTEST_READFILEINDIR_FUZZER_H
#define FUZZ_PROJECT_NAME "ReadFileInDir_fuzzer"
#endif

View File

@ -0,0 +1,36 @@
/*
* 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 "StartDynamicProcess_fuzzer.h"
#include "dynamic_service.h"
namespace OHOS {
bool FuzzStartDynamicProcess(const uint8_t* data, size_t size)
{
bool result = false;
if (!StartDynamicProcess(reinterpret_cast<const char*>(data))) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzStartDynamicProcess(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H
#define TEST_FUZZTEST_STARTDYNAMICPROCESS_FUZZER_H
#define FUZZ_PROJECT_NAME "StartDynamicProcess_fuzzer"
#endif

View File

@ -0,0 +1,36 @@
/*
* 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 "StopDynamicProcess_fuzzer.h"
#include "dynamic_service.h"
namespace OHOS {
bool FuzzStopDynamicProcess(const uint8_t* data, size_t size)
{
bool result = false;
if (!StopDynamicProcess(reinterpret_cast<const char*>(data))) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzStopDynamicProcess(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H
#define TEST_FUZZTEST_STOPDYNAMICPROCESS_FUZZER_H
#define FUZZ_PROJECT_NAME "StopDynamicProcess_fuzzer"
#endif

View File

@ -0,0 +1,35 @@
/*
* 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 "SystemDumpParameters_fuzzer.h"
#include "sys_param.h"
#include "fuzz_utils.h"
namespace OHOS {
bool FuzzSystemDumpParameters(const uint8_t* data, size_t size)
{
CloseStdout();
SystemDumpParameters(reinterpret_cast<int>(data));
return true;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemDumpParameters(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMDUMPPARAMETERS_FUZZER_H
#define TEST_FUZZTEST_SYSTEMDUMPPARAMETERS_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemDumpParameters_fuzzer"
#endif

View File

@ -0,0 +1,38 @@
/*
* 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 "SystemFindParameter_fuzzer.h"
#include "sys_param.h"
static ParamHandle handle;
namespace OHOS {
bool FuzzSystemFindParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemFindParameter(reinterpret_cast<const char*>(data), &handle)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemFindParameter(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMFINDPARAMETER_FUZZER_H
#define TEST_FUZZTEST_SYSTEMFINDPARAMETER_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemFindParameter_fuzzer"
#endif

View File

@ -0,0 +1,37 @@
/*
* 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 "SystemGetParameterCommitId_fuzzer.h"
#include "sys_param.h"
namespace OHOS {
bool FuzzSystemGetParameterCommitId(const uint8_t* data, size_t size)
{
bool result = false;
uint32_t commitId = 0;
if (!SystemGetParameterCommitId(reinterpret_cast<ParamHandle>(data), &commitId)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemGetParameterCommitId(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMGETPARAMETERCOMMITID_FUZZER_H
#define TEST_FUZZTEST_SYSTEMGETPARAMETERCOMMITID_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemGetParameterCommitId_fuzzer"
#endif

View File

@ -0,0 +1,37 @@
/*
* 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 "SystemGetParameterName_fuzzer.h"
#include "sys_param.h"
namespace OHOS {
bool FuzzSystemGetParameterName(const uint8_t* data, size_t size)
{
bool result = false;
char buffer[PARAM_NAME_LEN_MAX] = {0};
if (!SystemGetParameterName(reinterpret_cast<ParamHandle>(data), buffer, PARAM_NAME_LEN_MAX)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemGetParameterName(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMGETPARAMETERNAME_FUZZER_H
#define TEST_FUZZTEST_SYSTEMGETPARAMETERNAME_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemGetParameterName_fuzzer"
#endif

View File

@ -0,0 +1,38 @@
/*
* 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 "SystemGetParameterValue_fuzzer.h"
#include "sys_param.h"
namespace OHOS {
bool FuzzSystemGetParameterValue(const uint8_t* data, size_t size)
{
bool result = false;
char buffer[PARAM_CONST_VALUE_LEN_MAX] = {0};
uint32_t len = PARAM_CONST_VALUE_LEN_MAX;
if (!SystemGetParameterValue(reinterpret_cast<ParamHandle>(data), buffer, &len)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemGetParameterValue(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMGETPARAMETERVALUE_FUZZER_H
#define TEST_FUZZTEST_SYSTEMGETPARAMETERVALUE_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemGetParameterValue_fuzzer"
#endif

View File

@ -0,0 +1,40 @@
/*
* 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 "SystemGetParameter_fuzzer.h"
#include <iostream>
#include "sys_param.h"
namespace OHOS {
bool FuzzSystemGetParameter(const uint8_t* data, size_t size)
{
bool result = false;
char buffer[PARAM_CONST_VALUE_LEN_MAX] = {0};
uint32_t len = PARAM_CONST_VALUE_LEN_MAX;
if (!SystemGetParameter(reinterpret_cast<const char*>(data), buffer, &len)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemGetParameter(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMGETPARAMETER_FUZZER_H
#define TEST_FUZZTEST_SYSTEMGETPARAMETER_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemGetParameter_fuzzer"
#endif

View File

@ -0,0 +1,36 @@
/*
* 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 "SystemSetParameter_fuzzer.h"
#include "sys_param.h"
namespace OHOS {
bool FuzzSystemSetParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemSetParameter(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data))) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemSetParameter(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMSETPARAMETER_FUZZER_H
#define TEST_FUZZTEST_SYSTEMSETPARAMETER_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemSetParameter_fuzzer"
#endif

View File

@ -0,0 +1,70 @@
/*
* 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 "SystemTraversalParameter_fuzzer.h"
#include "fuzz_utils.h"
#include "init.h"
#include "securec.h"
#include "sys_param.h"
static void FakeShowParam(ParamHandle handle, void *cookie)
{
Cookie *nameAndValue = reinterpret_cast<Cookie*>(cookie);
char *name = nameAndValue->data;
unsigned int nameLen = nameAndValue->size;
char value[PARAM_CONST_VALUE_LEN_MAX] = {0};
SystemGetParameterName(handle, name, nameLen);
uint32_t size = PARAM_CONST_VALUE_LEN_MAX;
SystemGetParameterValue(handle, value, &size);
printf("\t%s = %s \n", name, value);
}
namespace OHOS {
bool FuzzSystemTraversalParameter(const uint8_t* data, size_t size)
{
bool result = false;
CloseStdout();
Cookie instance = {0, nullptr};
Cookie *cookie = &instance;
if (size <= 0) {
return false;
}
cookie->data = static_cast<char *>(malloc(size));
if (cookie->data == nullptr) {
return true;
}
cookie->size = size;
int ret = memcpy_s(cookie->data, size, data, size);
if (ret != EOK) {
return false;
}
if (!SystemTraversalParameter(FakeShowParam, reinterpret_cast<void*>(cookie))) {
result = true;
}
free(cookie->data);
cookie->data = nullptr;
cookie->size = 0;
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemTraversalParameter(data, size);
return 0;
}

View File

@ -0,0 +1,25 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMTRAVERSALPARAMETER_FUZZER_H
#define TEST_FUZZTEST_SYSTEMTRAVERSALPARAMETER_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemTraversalParameter_fuzzer"
typedef struct {
size_t size;
char *data;
} Cookie;
#endif

View File

@ -0,0 +1,36 @@
/*
* 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 "SystemWaitParameter_fuzzer.h"
#include "sys_param.h"
namespace OHOS {
bool FuzzSystemWaitParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemWaitParameter(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data), 1)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemWaitParameter(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMWAITPARAMETER_FUZZER_H
#define TEST_FUZZTEST_SYSTEMWAITPARAMETER_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemWaitParameter_fuzzer"
#endif

View File

@ -0,0 +1,47 @@
/*
* 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 "SystemWatchParameter_fuzzer.h"
#include "init.h"
#include "sys_param.h"
static void HandleParamChange(const char *key, const char *value, void *context)
{
if (key == nullptr || value == nullptr) {
return;
}
UNUSED(context);
printf("Receive parameter change %s %s \n", key, value);
}
namespace OHOS {
bool FuzzSystemWatchParameter(const uint8_t* data, size_t size)
{
bool result = false;
if (!SystemWatchParameter(reinterpret_cast<const char*>(data), HandleParamChange, NULL)) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzSystemWatchParameter(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_SYSTEMWATCHPARAMETER_FUZZER_H
#define TEST_FUZZTEST_SYSTEMWATCHPARAMETER_FUZZER_H
#define FUZZ_PROJECT_NAME "SystemWatchParameter_fuzzer"
#endif

View File

@ -0,0 +1,53 @@
/*
* 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 "UmountAllFstab_fuzzer.h"
#include <iostream>
#include "fs_manager/fs_manager.h"
#include "fuzz_utils.h"
namespace OHOS {
bool FuzzUmountAllWithFstabFile(const uint8_t* data, size_t size)
{
bool result = false;
FILE *pFile = nullptr;
pFile = fopen("fstab.test", "w+");
if (pFile == nullptr) {
std::cout << "[fuzz] open file fstab.test failed";
return false;
}
if (reinterpret_cast<int>(fwrite(data, 1, size, pFile)) != size) {
std::cout << "[fuzz] write data to fstab.test failed";
fclose(pFile);
return false;
}
fclose(pFile);
CloseStdout();
if (!UmountAllWithFstabFile("fstab.test")) {
result = true;
}
return result;
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::FuzzUmountAllWithFstabFile(data, size);
return 0;
}

View File

@ -0,0 +1,19 @@
/*
* 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.
*/
#ifndef TEST_FUZZTEST_UMOUNTALLFSTAB_FUZZER_H
#define TEST_FUZZTEST_UMOUNTALLFSTAB_FUZZER_H
#define FUZZ_PROJECT_NAME "UmountAllFstab_fuzzer"
#endif

25
test/fuzztest/project.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>100</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>2048</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,28 @@
/*
* 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 <fcntl.h>
#include <unistd.h>
#include "fuzz_utils.h"
void CloseStdout(void)
{
int fd = open("/dev/null", O_RDWR | O_CLOEXEC);
if (fd < 0) {
return;
}
dup2(fd, 1);
close(fd);
}

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
#ifndef FUZZ_UTILS_H
#define FUZZ_UTILS_H
void CloseStdout(void);
#endif