Skip to content

Commit 5d702f6

Browse files
Merge pull request #1363 from KFilipek/umfctlexec-size-check
[CTL] Add size check for umfCtlExec
2 parents c6d8e11 + cff9694 commit 5d702f6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/libumf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size) {
128128
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
129129
}
130130

131+
if ((arg == NULL && size != 0) || (arg != NULL && size == 0)) {
132+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
133+
}
134+
131135
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,
132136
CTL_QUERY_RUNNABLE, arg, size)
133137
? UMF_RESULT_ERROR_UNKNOWN

test/ctl/ctl_api.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ 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(umfCtlSet(name.c_str(), NULL, (void *)"test_value", 0),
357+
UMF_RESULT_ERROR_INVALID_ARGUMENT);
358+
ASSERT_EQ(umfCtlSet(name.c_str(), NULL, NULL, 10),
359+
UMF_RESULT_ERROR_INVALID_ARGUMENT);
360+
}
361+
354362
#ifdef PROVIDER_DEFAULTS_NOT_IMPLEMENTED_YET
355363
TEST_F(CtlTest, ctlDefaultMultithreadedProvider) {
356364
std::vector<std::thread> threads;

0 commit comments

Comments
 (0)