From 99a7f0c5d3311f93b53427d4c878c006be2c89e6 Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Fri, 1 Aug 2025 09:14:39 +0200 Subject: [PATCH 1/2] Fix null pointer dereference in createDevDaxParams() Fix null pointer dereference in createDevDaxParams(). It fixes the Coverity issue no. 485528. Signed-off-by: Lukasz Dorau --- test/pools/jemalloc_coarse_devdax.cpp | 3 +++ test/pools/scalable_coarse_devdax.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/pools/jemalloc_coarse_devdax.cpp b/test/pools/jemalloc_coarse_devdax.cpp index 8f96739aec..35a860bfa3 100644 --- a/test/pools/jemalloc_coarse_devdax.cpp +++ b/test/pools/jemalloc_coarse_devdax.cpp @@ -20,6 +20,9 @@ bool devDaxEnvSet() { void *createDevDaxParams() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); + if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + return nullptr; + } umf_devdax_memory_provider_params_handle_t params = NULL; umf_result_t res = diff --git a/test/pools/scalable_coarse_devdax.cpp b/test/pools/scalable_coarse_devdax.cpp index 6e27cd909e..066a8614ea 100644 --- a/test/pools/scalable_coarse_devdax.cpp +++ b/test/pools/scalable_coarse_devdax.cpp @@ -20,6 +20,9 @@ bool devDaxEnvSet() { void *createDevDaxParams() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); + if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + return nullptr; + } umf_devdax_memory_provider_params_handle_t params = NULL; umf_result_t res = From 3732792530d39500b690ce36ec5634258441035a Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Fri, 1 Aug 2025 12:57:06 +0200 Subject: [PATCH 2/2] Replace 0 with '\0' Signed-off-by: Lukasz Dorau --- examples/dram_and_fsdax/dram_and_fsdax.c | 2 +- test/ipc_devdax_prov_consumer.c | 4 ++-- test/ipc_devdax_prov_producer.c | 4 ++-- test/pools/jemalloc_coarse_devdax.cpp | 6 ++++-- test/pools/scalable_coarse_devdax.cpp | 6 ++++-- test/provider_devdax_memory.cpp | 5 +++-- test/provider_devdax_memory_ipc.cpp | 6 ++++-- test/provider_file_memory.cpp | 2 +- test/provider_file_memory_ipc.cpp | 2 +- 9 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/dram_and_fsdax/dram_and_fsdax.c b/examples/dram_and_fsdax/dram_and_fsdax.c index ad2d12392a..4486934d98 100644 --- a/examples/dram_and_fsdax/dram_and_fsdax.c +++ b/examples/dram_and_fsdax/dram_and_fsdax.c @@ -96,7 +96,7 @@ int main(void) { // - the UMF_TESTS_FSDAX_PATH environment variable to contain // a path to a file on this FSDAX device. char *path = getenv("UMF_TESTS_FSDAX_PATH"); - if (path == NULL || path[0] == 0) { + if (path == NULL || path[0] == '\0') { fprintf( stderr, "Warning: UMF_TESTS_FSDAX_PATH is not set, skipping testing ...\n"); diff --git a/test/ipc_devdax_prov_consumer.c b/test/ipc_devdax_prov_consumer.c index 760d075c83..105ddd864b 100644 --- a/test/ipc_devdax_prov_consumer.c +++ b/test/ipc_devdax_prov_consumer.c @@ -23,13 +23,13 @@ int main(int argc, char *argv[]) { int port = atoi(argv[1]); char *path = getenv("UMF_TESTS_DEVDAX_PATH"); - if (path == NULL || path[0] == 0) { + if (path == NULL || path[0] == '\0') { fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_PATH is not set\n"); return 0; } char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (size == NULL || size[0] == 0) { + if (size == NULL || size[0] == '\0') { fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set\n"); return 0; } diff --git a/test/ipc_devdax_prov_producer.c b/test/ipc_devdax_prov_producer.c index 39d5985990..2445db07ec 100644 --- a/test/ipc_devdax_prov_producer.c +++ b/test/ipc_devdax_prov_producer.c @@ -23,13 +23,13 @@ int main(int argc, char *argv[]) { int port = atoi(argv[1]); char *path = getenv("UMF_TESTS_DEVDAX_PATH"); - if (path == NULL || path[0] == 0) { + if (path == NULL || path[0] == '\0') { fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_PATH is not set\n"); return 0; } char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (size == NULL || size[0] == 0) { + if (size == NULL || size[0] == '\0') { fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set\n"); return 0; } diff --git a/test/pools/jemalloc_coarse_devdax.cpp b/test/pools/jemalloc_coarse_devdax.cpp index 35a860bfa3..8af7809970 100644 --- a/test/pools/jemalloc_coarse_devdax.cpp +++ b/test/pools/jemalloc_coarse_devdax.cpp @@ -10,7 +10,8 @@ bool devDaxEnvSet() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return false; } @@ -20,7 +21,8 @@ bool devDaxEnvSet() { void *createDevDaxParams() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return nullptr; } diff --git a/test/pools/scalable_coarse_devdax.cpp b/test/pools/scalable_coarse_devdax.cpp index 066a8614ea..83fa855279 100644 --- a/test/pools/scalable_coarse_devdax.cpp +++ b/test/pools/scalable_coarse_devdax.cpp @@ -10,7 +10,8 @@ bool devDaxEnvSet() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return false; } @@ -20,7 +21,8 @@ bool devDaxEnvSet() { void *createDevDaxParams() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return nullptr; } diff --git a/test/provider_devdax_memory.cpp b/test/provider_devdax_memory.cpp index b6b3299e01..b22f4fa291 100644 --- a/test/provider_devdax_memory.cpp +++ b/test/provider_devdax_memory.cpp @@ -123,7 +123,7 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) { umf_result_t umf_result; char *path = getenv("UMF_TESTS_DEVDAX_PATH"); - if (path == nullptr || path[0] == 0) { + if (path == nullptr || path[0] == '\0') { GTEST_SKIP() << "Test skipped, UMF_TESTS_DEVDAX_PATH is not set"; } @@ -169,7 +169,8 @@ using devdax_params_unique_handle_t = devdax_params_unique_handle_t create_devdax_params() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return devdax_params_unique_handle_t( nullptr, &umfDevDaxMemoryProviderParamsDestroy); } diff --git a/test/provider_devdax_memory_ipc.cpp b/test/provider_devdax_memory_ipc.cpp index dd9452e540..1db7011534 100644 --- a/test/provider_devdax_memory_ipc.cpp +++ b/test/provider_devdax_memory_ipc.cpp @@ -18,7 +18,8 @@ using umf_test::test; bool devDaxEnvSet() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return false; } @@ -28,7 +29,8 @@ bool devDaxEnvSet() { void *defaultDevDaxParamsCreate() { char *path = getenv("UMF_TESTS_DEVDAX_PATH"); char *size = getenv("UMF_TESTS_DEVDAX_SIZE"); - if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) { + if (path == nullptr || path[0] == '\0' || size == nullptr || + size[0] == '\0') { return nullptr; } diff --git a/test/provider_file_memory.cpp b/test/provider_file_memory.cpp index 4fae4ce338..c59223eb5a 100644 --- a/test/provider_file_memory.cpp +++ b/test/provider_file_memory.cpp @@ -119,7 +119,7 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) { umf_result_t umf_result; char *path = getenv("UMF_TESTS_FSDAX_PATH"); - if (path == nullptr || path[0] == 0) { + if (path == nullptr || path[0] == '\0') { GTEST_SKIP() << "Test skipped, UMF_TESTS_FSDAX_PATH is not set"; } diff --git a/test/provider_file_memory_ipc.cpp b/test/provider_file_memory_ipc.cpp index 7864876441..fe50d8408f 100644 --- a/test/provider_file_memory_ipc.cpp +++ b/test/provider_file_memory_ipc.cpp @@ -114,7 +114,7 @@ static std::vector getIpcFsDaxTestParamsList(void) { std::vector ipcFsDaxTestParamsList = {}; char *path = getenv("UMF_TESTS_FSDAX_PATH"); - if (path == nullptr || path[0] == 0) { + if (path == nullptr || path[0] == '\0') { // skipping the test, UMF_TESTS_FSDAX_PATH is not set return ipcFsDaxTestParamsList; }