From 2fc1f05b8e3cc9d34419bc679ef4e13bb3127be2 Mon Sep 17 00:00:00 2001 From: wangyikai Date: Thu, 8 Aug 2024 16:47:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4HdfUtilsFuzzTest=EF=BC=8C?= =?UTF-8?q?=E8=AF=A5=E6=8E=A5=E5=8F=A3=E6=97=A0=E9=9C=80fuzz=EF=BC=8C?= =?UTF-8?q?=E5=B7=B2=E8=A2=AB=E5=88=97=E5=85=A5=E7=94=B3=E8=AF=B7=E5=B1=8F?= =?UTF-8?q?=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyikai --- framework/test/fuzztest/BUILD.gn | 1 - .../utils_fuzzer/BUILD.gn | 54 ------------ .../utils_fuzzer/corpus/init | 7 -- .../utils_fuzzer/project.xml | 17 ---- .../utils_fuzzer/utils_fuzzer.cpp | 84 ------------------- .../utils_fuzzer/utils_fuzzer.h | 14 ---- 6 files changed, 177 deletions(-) delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp delete mode 100644 framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h diff --git a/framework/test/fuzztest/BUILD.gn b/framework/test/fuzztest/BUILD.gn index 00a9ab9fa..5abca4bb8 100644 --- a/framework/test/fuzztest/BUILD.gn +++ b/framework/test/fuzztest/BUILD.gn @@ -17,7 +17,6 @@ group("hdf_framework_fuzztest") { "devsvcmanagerstub_fuzzer:DevSvcManagerStubFuzzTest", "framework_fuzzer/hcs_fuzzer:HdfHcsFuzzTest", "framework_fuzzer/support/posix_fuzzer:HdfPosixFuzzTest", - "framework_utils_fuzzer/utils_fuzzer:HdfUtilsFuzzTest", "ioservice_fuzzer/ioserviceadapterobtain_fuzzer:IoserviceAdapterObtainFuzzTest", "ioservice_fuzzer/ioservicebind_fuzzer:IoserviceBindFuzzTest", "ioservice_fuzzer/ioservicegrouplisten_fuzzer:IoserviceGroupListenFuzzTest", diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn deleted file mode 100644 index 1760762dd..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/BUILD.gn +++ /dev/null @@ -1,54 +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") - -module_output_path = "hdf_core/hdf_core/framework_utils_fuzzer" - -hdf_framework_path = "../../../../../framework" -hdf_uhdf_path = "../../../../../adapter/uhdf2" -hdf_interfaces_path = "../../../../interfaces" - -ohos_fuzztest("HdfUtilsFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "$hdf_framework_path/test/fuzztest/framework_utils_fuzzer/utils_fuzzer" - - include_dirs = [ - "$hdf_uhdf_path/utils/include", - "$hdf_uhdf_path/hdi/include", - "$hdf_framework_path/include", - "$hdf_framework_path/utils/include", - "$hdf_interfaces_path/inner_api/hdi", - "$hdf_interfaces_path/inner_api/utils", - ] - - sources = [ - "$hdf_framework_path/utils/src/hdf_sbuf.c", - "$hdf_framework_path/utils/src/hdf_sbuf_impl_raw.c", - "$hdf_framework_path/utils/src/hdf_cstring.c", - "utils_fuzzer.cpp", - ] - - deps = [ - "../../../../../adapter/uhdf2/hdi:libhdi", - "../../../../../adapter/uhdf2/utils:libhdf_utils", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfUtilsFuzzTest" ] -} diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_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/framework_utils_fuzzer/utils_fuzzer/project.xml b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml deleted file mode 100644 index e47b18640..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp deleted file mode 100644 index 81a77affa..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.cpp +++ /dev/null @@ -1,84 +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 "utils_fuzzer.h" -#include "hdf_base.h" -#include "hdf_log.h" -#include "parcel.h" -#include -#include "osal_mem.h" -#include "hdi_support.h" -#include -#include "hdf_map.h" -#include "hdf_sbuf.h" -#include "hdf_sbuf_impl.h" -#include "hdf_cstring.h" -#include "hdf_thread_ex.h" -#include "osal_message.h" - -namespace OHOS { -static void HdfUtilsFuzzTest(const uint8_t *data, size_t size) -{ - if (data == nullptr) { - HDF_LOGE("%{public}s: data is nullptr!", __func__); - } - Map testMap; - Map testMap1; - MapInit(&testMap); - MapInit(&testMap1); - MapDelete(&testMap); - int num = 0; - int num1 = 1; - const char *name = "i2c"; - const char *name1 = "rtc"; - MapSet(&testMap1, name, &num, sizeof(int *)); - MapSet(&testMap1, name1, &num1, sizeof(int *)); - MapGet(&testMap1, ""); - MapGet(&testMap1, name); - MapErase(&testMap1, ""); - MapErase(&testMap1, name); - MapDelete(&testMap1); - - struct HdfMessage *message = HdfMessageObtain(size); - HdfMessageDelete(reinterpret_cast(message)); - - const char *str = "123"; - struct HdfCString *cstr = HdfCStringObtain(str); - HdfCStringRecycle(cstr); - struct HdfThread *thread = HdfThreadNewInstance(); - HdfThreadFreeInstance(thread); - - struct HdfSBuf *sbuf = HdfSbufObtainDefaultSize(); - struct HdfSBuf *copy = HdfSbufCopy(sbuf); - HdfSbufSetDataSize(copy, size); - HdfSbufGetDataSize(copy); - HdfSbufGetData(copy); - struct HdfSBufImpl *impl = HdfSbufGetImpl(copy); - if (impl == nullptr) { - impl = (struct HdfSBufImpl *)OsalMemCalloc(sizeof(struct HdfSBufImpl)); - } - struct HdfSBuf *newCopy = HdfSbufMove(copy); - HdfSbufTransDataOwnership(copy); - HdfSbufTypedObtainInplace(static_cast(size), impl); - impl->recycle(impl); - HdfSbufFlush(copy); - HdfSbufGetCapacity(copy); - HdfSbufRecycle(sbuf); - HdfSbufRecycle(copy); - HdfSbufRecycle(newCopy); - sbuf = nullptr; - copy = nullptr; -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::HdfUtilsFuzzTest(data, size); - return HDF_SUCCESS; -} \ No newline at end of file diff --git a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h b/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_fuzzer.h deleted file mode 100644 index 9b26247a8..000000000 --- a/framework/test/fuzztest/framework_utils_fuzzer/utils_fuzzer/utils_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 HDI_COLLECTION_FUZZER_H -#define HDI_COLLECTION_FUZZER_H - -#define FUZZ_PROJECT_NAME "collector_fuzzer" - -#endif // HDI_COLLECTION_FUZZER_H \ No newline at end of file -- Gitee