Skip to content

Commit 4f94df9

Browse files
committed
[CTL] Add size check for umfCtlExec
1 parent 3a4a335 commit 4f94df9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/libumf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) {
127127
if (name == NULL) {
128128
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
129129
}
130+
if ((arg == NULL && size != 0) || (arg != NULL && size == 0)) {
131+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
132+
}
130133

131134
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,
132135
CTL_QUERY_RUNNABLE, arg, size)

test/ctl/ctl_api.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ TEST_F(CtlTest, ctlSizeValidation) {
351351
p.freeResources();
352352
}
353353

354+
TEST_F(CtlTest, ctlExecInvalidSize) {
355+
std::string name = "umf.pool.default.disjoint.name";
356+
ASSERT_EQ(
357+
umfCtlSet(name.c_str(), NULL, (void *)"test_value", 0),
358+
UMF_RESULT_ERROR_INVALID_ARGUMENT);
359+
ASSERT_EQ(umfCtlSet(name.c_str(), NULL, NULL, 10),
360+
UMF_RESULT_ERROR_INVALID_ARGUMENT);
361+
}
362+
354363
#ifdef PROVIDER_DEFAULTS_NOT_IMPLEMENTED_YET
355364
TEST_F(CtlTest, ctlDefaultMultithreadedProvider) {
356365
std::vector<std::thread> threads;

0 commit comments

Comments
 (0)