Skip to content

Commit e05b3a7

Browse files
authored
Merge pull request #1473 from ldorau/Fix_null_pointer_dereference_in_createDevDaxParams
Fix null pointer dereference in createDevDaxParams()
2 parents 05e7555 + 3732792 commit e05b3a7

9 files changed

+26
-13
lines changed

examples/dram_and_fsdax/dram_and_fsdax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int main(void) {
9696
// - the UMF_TESTS_FSDAX_PATH environment variable to contain
9797
// a path to a file on this FSDAX device.
9898
char *path = getenv("UMF_TESTS_FSDAX_PATH");
99-
if (path == NULL || path[0] == 0) {
99+
if (path == NULL || path[0] == '\0') {
100100
fprintf(
101101
stderr,
102102
"Warning: UMF_TESTS_FSDAX_PATH is not set, skipping testing ...\n");

test/ipc_devdax_prov_consumer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ int main(int argc, char *argv[]) {
2323
int port = atoi(argv[1]);
2424

2525
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
26-
if (path == NULL || path[0] == 0) {
26+
if (path == NULL || path[0] == '\0') {
2727
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_PATH is not set\n");
2828
return 0;
2929
}
3030

3131
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
32-
if (size == NULL || size[0] == 0) {
32+
if (size == NULL || size[0] == '\0') {
3333
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set\n");
3434
return 0;
3535
}

test/ipc_devdax_prov_producer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ int main(int argc, char *argv[]) {
2323
int port = atoi(argv[1]);
2424

2525
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
26-
if (path == NULL || path[0] == 0) {
26+
if (path == NULL || path[0] == '\0') {
2727
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_PATH is not set\n");
2828
return 0;
2929
}
3030

3131
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
32-
if (size == NULL || size[0] == 0) {
32+
if (size == NULL || size[0] == '\0') {
3333
fprintf(stderr, "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set\n");
3434
return 0;
3535
}

test/pools/jemalloc_coarse_devdax.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
bool devDaxEnvSet() {
1111
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
1212
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
13-
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
13+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
14+
size[0] == '\0') {
1415
return false;
1516
}
1617

@@ -20,6 +21,10 @@ bool devDaxEnvSet() {
2021
void *createDevDaxParams() {
2122
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
2223
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
24+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
25+
size[0] == '\0') {
26+
return nullptr;
27+
}
2328

2429
umf_devdax_memory_provider_params_handle_t params = NULL;
2530
umf_result_t res =

test/pools/scalable_coarse_devdax.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
bool devDaxEnvSet() {
1111
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
1212
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
13-
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
13+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
14+
size[0] == '\0') {
1415
return false;
1516
}
1617

@@ -20,6 +21,10 @@ bool devDaxEnvSet() {
2021
void *createDevDaxParams() {
2122
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
2223
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
24+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
25+
size[0] == '\0') {
26+
return nullptr;
27+
}
2328

2429
umf_devdax_memory_provider_params_handle_t params = NULL;
2530
umf_result_t res =

test/provider_devdax_memory.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
123123
umf_result_t umf_result;
124124

125125
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
126-
if (path == nullptr || path[0] == 0) {
126+
if (path == nullptr || path[0] == '\0') {
127127
GTEST_SKIP() << "Test skipped, UMF_TESTS_DEVDAX_PATH is not set";
128128
}
129129

@@ -169,7 +169,8 @@ using devdax_params_unique_handle_t =
169169
devdax_params_unique_handle_t create_devdax_params() {
170170
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
171171
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
172-
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
172+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
173+
size[0] == '\0') {
173174
return devdax_params_unique_handle_t(
174175
nullptr, &umfDevDaxMemoryProviderParamsDestroy);
175176
}

test/provider_devdax_memory_ipc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ using umf_test::test;
1818
bool devDaxEnvSet() {
1919
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
2020
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
21-
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
21+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
22+
size[0] == '\0') {
2223
return false;
2324
}
2425

@@ -28,7 +29,8 @@ bool devDaxEnvSet() {
2829
void *defaultDevDaxParamsCreate() {
2930
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
3031
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
31-
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
32+
if (path == nullptr || path[0] == '\0' || size == nullptr ||
33+
size[0] == '\0') {
3234
return nullptr;
3335
}
3436

test/provider_file_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
119119
umf_result_t umf_result;
120120

121121
char *path = getenv("UMF_TESTS_FSDAX_PATH");
122-
if (path == nullptr || path[0] == 0) {
122+
if (path == nullptr || path[0] == '\0') {
123123
GTEST_SKIP() << "Test skipped, UMF_TESTS_FSDAX_PATH is not set";
124124
}
125125

test/provider_file_memory_ipc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static std::vector<ipcTestParams> getIpcFsDaxTestParamsList(void) {
114114
std::vector<ipcTestParams> ipcFsDaxTestParamsList = {};
115115

116116
char *path = getenv("UMF_TESTS_FSDAX_PATH");
117-
if (path == nullptr || path[0] == 0) {
117+
if (path == nullptr || path[0] == '\0') {
118118
// skipping the test, UMF_TESTS_FSDAX_PATH is not set
119119
return ipcFsDaxTestParamsList;
120120
}

0 commit comments

Comments
 (0)