From f9cabeed54e9a6ad5859f8e7165a45a7e22fb6ce Mon Sep 17 00:00:00 2001 From: huyx Date: Fri, 18 Oct 2024 10:43:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E7=94=A8=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyx --- framework/test/fuzztest/BUILD.gn | 4 - .../framework_fuzzer/hcs_fuzzer/BUILD.gn | 40 --- .../framework_fuzzer/hcs_fuzzer/corpus/init | 7 - .../hcs_fuzzer/hcs_fuzzer.cpp | 281 ------------------ .../framework_fuzzer/hcs_fuzzer/hcs_fuzzer.h | 14 - .../framework_fuzzer/hcs_fuzzer/project.xml | 17 -- .../support/posix_fuzzer/BUILD.gn | 40 --- .../support/posix_fuzzer/corpus/init | 7 - .../support/posix_fuzzer/posix_fuzzer.cpp | 185 ------------ .../support/posix_fuzzer/posix_fuzzer.h | 14 - .../support/posix_fuzzer/project.xml | 17 -- .../uhdf2_ipc_fuzzer/ipc_fuzzer/BUILD.gn | 42 --- .../uhdf2_ipc_fuzzer/ipc_fuzzer/corpus/init | 7 - .../ipc_fuzzer/hdfipc_fuzzer.cpp | 48 --- .../ipc_fuzzer/hdfipc_fuzzer.h | 14 - .../uhdf2_ipc_fuzzer/ipc_fuzzer/project.xml | 17 -- .../inner_api_utils_fuzzer/BUILD.gn | 39 --- .../inner_api_utils_fuzzer/corpus/init | 7 - .../innerapi_utils_fuzzer.cpp | 69 ----- .../innerapi_utils_fuzzer.h | 14 - .../inner_api_utils_fuzzer/project.xml | 17 -- 21 files changed, 900 deletions(-) delete mode 100644 framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/BUILD.gn delete mode 100644 framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/corpus/init delete mode 100644 framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_fuzzer.cpp delete mode 100644 framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_fuzzer.h delete mode 100644 framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/project.xml delete mode 100644 framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/BUILD.gn delete mode 100644 framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/corpus/init delete mode 100644 framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_fuzzer.cpp delete mode 100644 framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_fuzzer.h delete mode 100644 framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/project.xml delete mode 100644 framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/BUILD.gn delete mode 100644 framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/corpus/init delete mode 100644 framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.cpp delete mode 100644 framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.h delete mode 100644 framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/project.xml delete mode 100644 framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/BUILD.gn delete mode 100644 framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/corpus/init delete mode 100644 framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.cpp delete mode 100644 framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.h delete mode 100644 framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/project.xml diff --git a/framework/test/fuzztest/BUILD.gn b/framework/test/fuzztest/BUILD.gn index 5abca4bb8..c9150449c 100644 --- a/framework/test/fuzztest/BUILD.gn +++ b/framework/test/fuzztest/BUILD.gn @@ -15,8 +15,6 @@ group("hdf_framework_fuzztest") { "devmgr_service_fuzzer:ServiceFuzzTest", "devmgrservicestub_fuzzer:DevmgrServiceStubFuzzTest", "devsvcmanagerstub_fuzzer:DevSvcManagerStubFuzzTest", - "framework_fuzzer/hcs_fuzzer:HdfHcsFuzzTest", - "framework_fuzzer/support/posix_fuzzer:HdfPosixFuzzTest", "ioservice_fuzzer/ioserviceadapterobtain_fuzzer:IoserviceAdapterObtainFuzzTest", "ioservice_fuzzer/ioservicebind_fuzzer:IoserviceBindFuzzTest", "ioservice_fuzzer/ioservicegrouplisten_fuzzer:IoserviceGroupListenFuzzTest", @@ -29,8 +27,6 @@ group("hdf_framework_fuzztest") { "servmgr_cpp_fuzzer/servstatlistenerstub_fuzzer:ServStatListenerStubFuzzTest", "servmgr_cpp_fuzzer/unregisterservicestatuslistener_fuzzer:UnregisterServiceStatusListenerFuzzTest", "syscall_fuzzer/syscall_fuzzer:SyscallFuzzTest", - "uhdf2_ipc_fuzzer/ipc_fuzzer:HdfIpcFuzzTest", "uhdf2_utils_fuzzer/hdfxcollie_fuzzer:HdfXCollieFuzzTest", - "uhdf2_utils_fuzzer/inner_api_utils_fuzzer:HdfInnerApiUtilsFuzzTest", ] } diff --git a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/BUILD.gn b/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/BUILD.gn deleted file mode 100644 index 95b953bd1..000000000 --- a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/BUILD.gn +++ /dev/null @@ -1,40 +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_fuzzer" - -hdf_framework_path = "../../../../../framework" -hdf_uhdf_path = "../../../../../adapter/uhdf2" - -ohos_fuzztest("HdfHcsFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "$hdf_framework_path/test/fuzztest/framework_fuzzer/hcs_fuzzer" - - include_dirs = [ "$hdf_uhdf_path/utils/include" ] - - sources = [ "hcs_fuzzer.cpp" ] - - deps = [ - "$hdf_uhdf_path/pub_utils:libpub_utils", - "$hdf_uhdf_path/utils:libhdf_utils", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfHcsFuzzTest" ] -} diff --git a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/corpus/init b/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4..000000000 --- a/framework/test/fuzztest/framework_fuzzer/hcs_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_fuzzer/hcs_fuzzer/hcs_fuzzer.cpp b/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_fuzzer.cpp deleted file mode 100644 index ed9946430..000000000 --- a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_fuzzer.cpp +++ /dev/null @@ -1,281 +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 "hcs_fuzzer.h" - -#include "hcs_tree_if.h" -#include "hdf_base.h" -#include "hdf_core_log.h" -#include "securec.h" - -namespace OHOS { -constexpr size_t THRESHOLD = 10; -#define HDF_LOG_TAG hcs_fuzzer_fuzzer - -enum FuncId { - HCS_HCSGETBOOL, - HCS_HCSGETUINT8, - HCS_HCSGETUINT32, - HCS_HCSGETUINT64, - HCS_HCSGETUINT8ARRAYELEM, - HCS_HCSGETUINT16ARRAYELEM, - HCS_HCSGETUINT32ARRAYELEM, - HCS_HCSGETUINT64ARRAYELEM, - HCS_END -}; - -void FuncHcsGetBool(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - HcsGetBool(&node, attrName); - return; -} - -void FuncHcsGetUint8(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint8_t value = 0; - uint8_t def = 0; - - HcsGetUint8(&node, attrName, &value, def); - return; -} - -void FuncHcsGetUint32(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint32_t value = 0; - uint32_t def = 0; - - HcsGetUint32(&node, attrName, &value, def); - return; -} - -void FuncHcsGetUint64(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint64_t value = 0; - uint64_t def = 0; - - HcsGetUint64(&node, attrName, &value, def); - return; -} - -void FuncHcsGetUint8ArrayElem(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint32_t index = 0; - uint8_t value = 0; - uint8_t def = 0; - - HcsGetUint8ArrayElem(&node, attrName, index, &value, def); - return; -} - -void FuncHcsGetUint16ArrayElem(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint32_t index = 0; - uint16_t value = 0; - uint16_t def = 0; - - HcsGetUint16ArrayElem(&node, attrName, index, &value, def); - return; -} - -void FuncHcsGetUint32ArrayElem(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint32_t index = 0; - uint32_t value = 0; - uint32_t def = 0; - - HcsGetUint32ArrayElem(&node, attrName, index, &value, def); - return; -} - -void FuncHcsGetUint64ArrayElem(const uint8_t *data, size_t size) -{ - if (size < sizeof(struct DeviceResourceNode)) { - return; - } - - struct DeviceResourceNode node; - size_t sz = sizeof(struct DeviceResourceNode); - if (memcpy_s(&node, sz, data, sz) != EOK) { - return; - } - node.name = "nothing"; - node.attrData = NULL; - node.parent = NULL; - node.child = NULL; - node.sibling = NULL; - const char *attrName = "nothing"; - uint32_t index = 0; - uint64_t value = 0; - uint64_t def = 0; - - HcsGetUint64ArrayElem(&node, attrName, index, &value, def); - return; -} - -void FuncSwitch(uint32_t cmd, const uint8_t *data, size_t size) -{ - switch (cmd) { - case HCS_HCSGETBOOL: { - FuncHcsGetBool(data, size); - break; - } - case HCS_HCSGETUINT8: { - FuncHcsGetUint8(data, size); - break; - } - case HCS_HCSGETUINT32: { - FuncHcsGetUint32(data, size); - break; - } - case HCS_HCSGETUINT64: { - FuncHcsGetUint64(data, size); - break; - } - case HCS_HCSGETUINT8ARRAYELEM: { - FuncHcsGetUint8ArrayElem(data, size); - break; - } - case HCS_HCSGETUINT16ARRAYELEM: { - FuncHcsGetUint16ArrayElem(data, size); - break; - } - case HCS_HCSGETUINT32ARRAYELEM: { - FuncHcsGetUint32ArrayElem(data, size); - break; - } - case HCS_HCSGETUINT64ARRAYELEM: { - FuncHcsGetUint64ArrayElem(data, size); - break; - } - default: - return; - } -} - -void TraverseAllFunc(const uint8_t *data, size_t size) -{ - for (uint32_t cmd = 0; cmd < HCS_END; cmd++) { - FuncSwitch(cmd, data, size); - } -} -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - if (size < OHOS::THRESHOLD) { - return HDF_SUCCESS; - } - - OHOS::TraverseAllFunc(data, size); - return HDF_SUCCESS; -} diff --git a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_fuzzer.h b/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_fuzzer.h deleted file mode 100644 index 008821b93..000000000 --- a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/hcs_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_HCS_H -#define HDF_HCS_H - -#define FUZZ_PROJECT_NAME "hcs_fuzzer" - -#endif // HDF_HCS_H \ No newline at end of file diff --git a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/project.xml b/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/project.xml deleted file mode 100644 index c39057510..000000000 --- a/framework/test/fuzztest/framework_fuzzer/hcs_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 0 - - 10 - - 128 - - diff --git a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/BUILD.gn b/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/BUILD.gn deleted file mode 100644 index 15803fc85..000000000 --- a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/BUILD.gn +++ /dev/null @@ -1,40 +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_fuzzer" - -hdf_framework_path = "../../../../../../framework" -hdf_uhdf_path = "../../../../../../adapter/uhdf2" - -ohos_fuzztest("HdfPosixFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "$hdf_framework_path/test/fuzztest/framework_fuzzer/support/posix_fuzzer" - - include_dirs = [ "$hdf_uhdf_path/utils/include" ] - - sources = [ "posix_fuzzer.cpp" ] - - deps = [ - "$hdf_uhdf_path/pub_utils:libpub_utils", - "$hdf_uhdf_path/utils:libhdf_utils", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfPosixFuzzTest" ] -} diff --git a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/corpus/init b/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4..000000000 --- a/framework/test/fuzztest/framework_fuzzer/support/posix_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_fuzzer/support/posix_fuzzer/posix_fuzzer.cpp b/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_fuzzer.cpp deleted file mode 100644 index 6836317e3..000000000 --- a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_fuzzer.cpp +++ /dev/null @@ -1,185 +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 "hdf_base.h" -#include "hdf_core_log.h" -#include "osal_mem.h" -#include "osal_sem.h" -#include "osal_time.h" -#include "osal_spinlock.h" -#include "posix_fuzzer.h" -#include - -namespace OHOS { -constexpr size_t THRESHOLD = 10; -#define HDF_LOG_TAG posix_fuzzer - -enum FuncId { - POSIX_OSALMEMALLOC, - POSIX_OSALMEMCALLOC, - POSIX_OSALMEMALLOCALIGN, - POSIX_OSALSEMWAIT, - POSIX_OSALSEMPOST, - POSIX_OSALSPINLOCK, - POSIX_OSALTIME, - HCS_END -}; - -void FuncOsalMemAlloc(const uint8_t *data, size_t size) -{ - if (size < sizeof(size_t)) { - return; - } - - size_t sz = *(size_t *)data; - uint8_t *mem = (uint8_t *)OsalMemAlloc(sz); - if (mem != nullptr) { - OsalMemFree(mem); - } - return; -} - -void FuncOsalMemCalloc(const uint8_t *data, size_t size) -{ - if (size < sizeof(size_t)) { - return; - } - - size_t sz = *(size_t *)data; - uint8_t *mem = (uint8_t *)OsalMemCalloc(sz); - if (mem != nullptr) { - OsalMemFree(mem); - } - return; -} - -void FuncOsalMemAllocAlign(const uint8_t *data, size_t size) -{ - if (size < sizeof(size_t)) { - return; - } - size_t alignment = 8; - size_t sz = 0; - - uint8_t *mem = (uint8_t *)OsalMemAllocAlign(alignment, sz); - if (mem != nullptr) { - OsalMemFree(mem); - } - const size_t NUM = 4; - sz = NUM; - mem = (uint8_t *)OsalMemAllocAlign(alignment, sz); - if (mem != nullptr) { - OsalMemFree(mem); - } - return; -} - -void FuncOsalSemWait(const uint8_t *data, size_t size) -{ - OsalSemWait(NULL, 0); - - struct OsalSem sem; - OsalSemInit(&sem, 1); - OsalSemWait(&sem, ~HDF_WAIT_FOREVER); - OsalSemDestroy(&sem); - return; -} - -void FuncOsalSemPost(const uint8_t *data, size_t size) -{ - struct OsalSem sem; - OsalSemInit(&sem, 1); - OsalSemPost(&sem); - OsalSemDestroy(&sem); - return; -} - -void FuncOsalSpinLock(const uint8_t *data, size_t size) -{ - OsalSpinInit(NULL); - OsalSpinlock spinlock; - OsalSpinInit(&spinlock); - const uint32_t SLEEPTIME = 2000; - std::thread thrd([&spinlock] { - OsalMSleep(SLEEPTIME); - OsalSpinUnlock(&spinlock); - }); - OsalSpinLock(&spinlock); - OsalSpinDestroy(&spinlock); - thrd.join(); - return; -} - -void FuncOsalTime(const uint8_t *data, size_t size) -{ - OsalGetTime(NULL); - OsalTimespec start, end, diff; - OsalGetTime(&start); - OsalGetTime(&end); - OsalDiffTime(&start, &end, &diff); - OsalUSleep(1); - OsalUDelay(1); - OsalMDelay(1); - uint64_t st = OsalGetSysTimeMs(); - (void)st; - return; -} - -void FuncSwitch(uint32_t cmd, const uint8_t *data, size_t size) -{ - switch (cmd) { - case POSIX_OSALMEMALLOC: { - FuncOsalMemAlloc(data, size); - break; - } - case POSIX_OSALMEMCALLOC: { - FuncOsalMemCalloc(data, size); - break; - } - case POSIX_OSALMEMALLOCALIGN: { - FuncOsalMemAllocAlign(data, size); - break; - } - case POSIX_OSALSEMWAIT: { - FuncOsalSemWait(data, size); - break; - } - case POSIX_OSALSEMPOST: { - FuncOsalSemPost(data, size); - break; - } - case POSIX_OSALSPINLOCK: { - FuncOsalSpinLock(data, size); - break; - } - case POSIX_OSALTIME: { - FuncOsalTime(data, size); - break; - } - default: - return; - } -} - -void TraverseAllFunc(const uint8_t *data, size_t size) -{ - for (uint32_t cmd = 0; cmd < HCS_END; cmd++) { - FuncSwitch(cmd, data, size); - } -} -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - if (size < OHOS::THRESHOLD) { - return HDF_SUCCESS; - } - - OHOS::TraverseAllFunc(data, size); - return HDF_SUCCESS; -} diff --git a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_fuzzer.h b/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_fuzzer.h deleted file mode 100644 index c30667a39..000000000 --- a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/posix_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_POSIX_H -#define HDF_POSIX_H - -#define FUZZ_PROJECT_NAME "posix_fuzzer" - -#endif // HDF_POSIX_H \ No newline at end of file diff --git a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/project.xml b/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/project.xml deleted file mode 100644 index c39057510..000000000 --- a/framework/test/fuzztest/framework_fuzzer/support/posix_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 0 - - 10 - - 128 - - diff --git a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/BUILD.gn b/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/BUILD.gn deleted file mode 100644 index 73c096d68..000000000 --- a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/BUILD.gn +++ /dev/null @@ -1,42 +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/uhdf2_ipc_fuzzer" - -hdf_framework_path = "../../../../../framework" -hdf_uhdf_path = "../../../../../adapter/uhdf2" - -ohos_fuzztest("HdfIpcFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "$hdf_framework_path/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer" - - include_dirs = [ - "$hdf_uhdf_path/utils/include", - "$hdf_uhdf_path/ipc/include", - "$hdf_framework_path/include", - ] - - sources = [ "hdfipc_fuzzer.cpp" ] - deps = [ "../../../../../adapter/uhdf2/utils:libhdf_utils" ] - - external_deps = [ - "c_utils:utils", - "hdf_core:libhdf_ipc_adapter", - "hilog:libhilog", - "ipc:ipc_single", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfIpcFuzzTest" ] -} diff --git a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/corpus/init b/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4..000000000 --- a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_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_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.cpp b/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.cpp deleted file mode 100644 index b127b6095..000000000 --- a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.cpp +++ /dev/null @@ -1,48 +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 "hdfipc_fuzzer.h" -#include "hdf_remote_adapter.h" -#include "hdf_core_log.h" -#include "parcel.h" -#include -#include -#include "hdf_base.h" - -namespace OHOS { -static void HdfIpcFuzzTest(const uint8_t *data, size_t size) -{ - if (data == nullptr) { - HDF_LOGE("%{public}s: data is nullptr!", __func__); - } - - Parcel parcel; - parcel.WriteBuffer(data, size); - const char *interfaceName = parcel.ReadCString(); - - struct HdfRemoteService *service = HdfRemoteAdapterObtain(); - if (service == nullptr) { - HDF_LOGE("%{public}s: serviceSet is nullptr!", __func__); - } - - HdfRemoteAdapterAddService(interfaceName, service); - HdfRemoteAdapterGetService(interfaceName); - - struct HdfDeathRecipient* recipient = nullptr; - HdfRemoteAdapterAddDeathRecipient(service, recipient); - HdfRemoteAdapterRemoveDeathRecipient(service, recipient); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::HdfIpcFuzzTest(data, size); - return HDF_SUCCESS; -} \ No newline at end of file diff --git a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.h b/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_fuzzer.h deleted file mode 100644 index ad1de3ab5..000000000 --- a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/hdfipc_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 IPC_ONREMOTEREQUEST_FUZZER_H -#define IPC_ONREMOTEREQUEST_FUZZER_H - -#define FUZZ_PROJECT_NAME "hdfipc_fuzzer" - -#endif // IPC_ONREMOTEREQUEST_FUZZER_H \ No newline at end of file diff --git a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/project.xml b/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/project.xml deleted file mode 100644 index e47b18640..000000000 --- a/framework/test/fuzztest/uhdf2_ipc_fuzzer/ipc_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/BUILD.gn b/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/BUILD.gn deleted file mode 100644 index 52e359a41..000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_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") - -module_output_path = "hdf_core/hdf_core/uhdf2_utils_fuzzer" - -hdf_framework_path = "../../../../../framework" -hdf_uhdf_path = "../../../../../adapter/uhdf2" - -ohos_fuzztest("HdfInnerApiUtilsFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = "$hdf_framework_path/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer" - - include_dirs = [ "$hdf_uhdf_path/utils/include" ] - - sources = [ "innerapi_utils_fuzzer.cpp" ] - - deps = [ - "$hdf_uhdf_path/pub_utils:libpub_utils", - "$hdf_uhdf_path/utils:libhdf_utils", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":HdfInnerApiUtilsFuzzTest" ] -} diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/corpus/init b/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/corpus/init deleted file mode 100644 index f707fb4e4..000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_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/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.cpp b/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.cpp deleted file mode 100644 index 8f88a1d19..000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.cpp +++ /dev/null @@ -1,69 +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 "innerapi_utils_fuzzer.h" - -#include "hdf_dlist.h" -#include "hdf_base.h" -#include "hdf_core_log.h" - -namespace OHOS { -constexpr size_t THRESHOLD = 10; -#define HDF_LOG_TAG innerapi_utils_fuzzer - -enum FuncId { - INNERAPI_UTILS_DLISTINSERTHEAD, - INNERAPI_UTILS_END -}; - -void FuncdListInsertHead(const uint8_t *data, size_t size) -{ - (void)data; - constexpr uint16_t cnt = 2; - if (size < sizeof(struct DListHead) * cnt) { - return; - } - - struct DListHead entry; - struct DListHead head; - DListHeadInit(&head); - DListInsertHead(&entry, &head); - return; -} - - -void FuncSwitch(uint32_t cmd, const uint8_t *data, size_t size) -{ - switch (cmd) { - case INNERAPI_UTILS_DLISTINSERTHEAD: { - FuncdListInsertHead(data, size); - break; - } - - default: - return; - } -} - -void TraverseAllFunc(const uint8_t *data, size_t size) -{ - for (uint32_t cmd = 0; cmd < INNERAPI_UTILS_END; cmd++) { - FuncSwitch(cmd, data, size); - } -} -} - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - if (size < OHOS::THRESHOLD) { - return HDF_SUCCESS; - } - - OHOS::TraverseAllFunc(data, size); - return HDF_SUCCESS; -} diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.h b/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_utils_fuzzer.h deleted file mode 100644 index 3bf39b55e..000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/innerapi_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 HDF_INNER_API_UTILS_H -#define HDF_INNER_API_UTILS_H - -#define FUZZ_PROJECT_NAME "innerapi_utils_fuzzer" - -#endif // HDF_INNER_API_UTILS_H \ No newline at end of file diff --git a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/project.xml b/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/project.xml deleted file mode 100644 index c39057510..000000000 --- a/framework/test/fuzztest/uhdf2_utils_fuzzer/inner_api_utils_fuzzer/project.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 0 - - 10 - - 128 - - -- Gitee