Skip to content

Commit 4ccec38

Browse files
committed
Check input parameter in umfGetIPCHandle function
1 parent 44dc69a commit 4ccec38

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ipc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ umf_result_t umfPoolGetIPCHandleSize(umf_memory_pool_handle_t hPool,
5151

5252
umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
5353
size_t *size) {
54+
if (ptr == NULL || umfIPCHandle == NULL || size == NULL) {
55+
LOG_ERR("invalid arguments.");
56+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
57+
}
58+
5459
size_t ipcHandleSize = 0;
5560
umf_alloc_info_t allocInfo;
5661
umf_result_t ret = umfMemoryTrackerGetAllocInfo(ptr, &allocInfo);

test/ipcFixtures.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ TEST_P(umfIpcTest, GetIPCHandleSize) {
122122
EXPECT_GT(size, 0);
123123
}
124124

125+
TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
126+
constexpr size_t SIZE = 100;
127+
umf_ipc_handle_t ipcHandle = nullptr;
128+
size_t handleSize = 0;
129+
umf_result_t ret = umfGetIPCHandle(nullptr, &ipcHandle, &handleSize);
130+
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
131+
132+
umf::pool_unique_handle_t pool = makePool();
133+
int *ptr = (int *)umfPoolMalloc(pool.get(), SIZE);
134+
EXPECT_NE(ptr, nullptr);
135+
136+
ret = umfGetIPCHandle(ptr, nullptr, &handleSize);
137+
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
138+
139+
ret = umfGetIPCHandle(ptr, &ipcHandle, nullptr);
140+
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
141+
}
142+
125143
TEST_P(umfIpcTest, BasicFlow) {
126144
constexpr size_t SIZE = 100;
127145
std::vector<int> expected_data(SIZE);

0 commit comments

Comments
 (0)