diff --git a/framework/test/fuzztest/BUILD.gn b/framework/test/fuzztest/BUILD.gn index c9150449c32e3978ea1a2755bd0b5244b8f5acce..69830250b6150b36ea9414ab80870e63eed5a647 100644 --- a/framework/test/fuzztest/BUILD.gn +++ b/framework/test/fuzztest/BUILD.gn @@ -27,6 +27,5 @@ group("hdf_framework_fuzztest") { "servmgr_cpp_fuzzer/servstatlistenerstub_fuzzer:ServStatListenerStubFuzzTest", "servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer:UnregisterServiceStatusListenerFuzzTest", "syscall_fuzzer/syscall_fuzzer:SyscallFuzzTest", - "uhdf2_utils_fuzzer/hdfxcollie_fuzzer:HdfXCollieFuzzTest", ] } diff --git a/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp b/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp index 395184474a3862fea2f919be8557a2ccade861d5..c6e16ea0b00aabd62d6d5ebc5e56ed9fc976d867 100644 --- a/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp +++ b/framework/test/fuzztest/devicemanagerstart_fuzzer/devicemanagerstart_fuzzer.cpp @@ -10,6 +10,7 @@ #include "hdf_base.h" #include "hdf_core_log.h" +#include "hdf_sbuf.h" #ifdef __cplusplus extern "C" { @@ -26,7 +27,7 @@ extern "C" { #define HDF_LOG_TAG devicemanagerstart_fuzzer -static int DeviceManagerStartServiceFuzzTest() +static int DeviceManagerStartServiceFuzzTest(const uint8_t *data, size_t size) { HDF_LOGI("start hdf device manager fuzzer"); int status = HDF_FAILURE; @@ -54,6 +55,17 @@ static int DeviceManagerStartServiceFuzzTest() HDF_LOGI("device manager fuzzer skip loop"); } } + struct HdfSBuf *dataBuf = HdfSbufTypedObtain(SBUF_IPC); + if (dataBuf == nullptr) { + HDF_LOGE("%{public}s:%{public}d: failed to create data buf", __func__, __LINE__); + return false; + } + + if (!HdfSbufWriteBuffer(dataBuf, data, size)) { + HDF_LOGE("%{public}s:%{public}d: failed to write data", __func__, __LINE__); + HdfSbufRecycle(dataBuf); + return false; + } HDF_LOGI("end of hdf device manager fuzzer, status is %{public}d", status); return status; @@ -66,7 +78,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) return ret; } - ret = DeviceManagerStartServiceFuzzTest(); + ret = DeviceManagerStartServiceFuzzTest(data, size); if (ret != HDF_SUCCESS) { HDF_LOGE("DeviceManagerStartServiceFuzzTest failed, ret is %{public}d", ret); return ret; diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn deleted file mode 100644 index aeb320049e4dcf75e24b41105bd93041afb11e10..0000000000000000000000000000000000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/BUILD.gn +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# -# HDF is dual licensed: you can use it either under the terms of -# the GPL, or the BSD license, at your option. -# See the LICENSE file in the root of this repository for complete details. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") - -module_output_path = "hdf_core/hdf_core/uhdf2_utils_fuzzer" - -ohos_fuzztest("HdfXCollieFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "$hdf_framework_path/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer" - - include_dirs = [ "$hdf_uhdf_path/utils/include" ] - - sources = [ "hdfxcollie_fuzzer.cpp" ] - - deps = [ "$hdf_uhdf_path/pub_utils:libpub_utils" ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] - - if (hicollie_enabled) { - defines = [ "HDFHICOLLIE_ENABLE" ] - } -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfXCollieFuzzTest" ] -} diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/corpus/init b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4acfe262dfeb05dbbae64043e18526fb..0000000000000000000000000000000000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/corpus/init +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# -# HDF is dual licensed: you can use it either under the terms of -# the GPL, or the BSD license, at your option. -# See the LICENSE file in the root of this repository for complete details. - -FUZZ \ No newline at end of file diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp deleted file mode 100644 index 899721282fa63cb2c69fa22d8c5c8c92fa38b14c..0000000000000000000000000000000000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "hdfxcollie_fuzzer.h" - -#include "hdf_xcollie.h" -#include "hdf_base.h" -#include "hdf_core_log.h" -#define HDF_LOG_TAG hdfxcollie_fuzzer - -static int HdfXCollieFuzzTest() -{ - ::OHOS::HdfXCollie& inst = ::OHOS::HdfXCollie::GetInstance(); - (void)inst; - return HDF_SUCCESS; -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - int ret = HDF_FAILURE; - ret = HdfXCollieFuzzTest(); - if (ret != HDF_SUCCESS) { - HDF_LOGE("HdfXCollieFuzzTest failed, ret is %{public}d", ret); - return ret; - } - return HDF_SUCCESS; -} diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.h b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.h deleted file mode 100644 index 2d92aa543faace456abfd7894ca93a2db2f3da87..0000000000000000000000000000000000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/hdfxcollie_fuzzer.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef HDF_XCOLLIE_FUZZER_H -#define HDF_XCOLLIE_FUZZER_H - -#define FUZZ_PROJECT_NAME "hdfxcollie_fuzzer" - -#endif // HDF_XCOLLIE_FUZZER_H \ No newline at end of file diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/project.xml b/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/project.xml deleted file mode 100644 index c390575101bdbc1d0df5bd1e5ff4a077c888604d..0000000000000000000000000000000000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/hdfxcollie_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 0 - - 10 - - 128 - -