Skip to content

Commit

Permalink
Enforce non-null argv values on rcl_init(). (#388)
Browse files Browse the repository at this point in the history
* Enforce non-null argv values on rcl_init().

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Adds test case for null argv values on rcl_init().

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored Feb 12, 2019
1 parent 5ec52d0 commit 4710751
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rcl/src/rcl/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ rcl_init(

if (argc > 0) {
RCL_CHECK_ARGUMENT_FOR_NULL(argv, RCL_RET_INVALID_ARGUMENT);
for (int i = 0; i < argc; ++i) {
RCL_CHECK_ARGUMENT_FOR_NULL(argv[i], RCL_RET_INVALID_ARGUMENT);
}
} else {
if (NULL != argv) {
RCL_SET_ERROR_MSG("argc is <= 0, but argv is not NULL");
Expand Down
6 changes: 6 additions & 0 deletions rcl/test/rcl/test_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ TEST_F(CLASSNAME(TestRCLFixture, RMW_IMPLEMENTATION), test_rcl_init_and_ok_and_s
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
rcl_reset_error();
ASSERT_FALSE(rcl_context_is_valid(&context));
// If argc is not 0, argv is not null but contains one, it should be an invalid argument.
const char * invalid_args[] = {"some-arg", nullptr};
ret = rcl_init(2, invalid_args, &init_options, &context);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret);
rcl_reset_error();
ASSERT_FALSE(rcl_context_is_valid(&context));
// If either the allocate or deallocate function pointers are not set, it should be invalid arg.
init_options.impl->allocator.allocate = nullptr;
ret = rcl_init(0, nullptr, &init_options, &context);
Expand Down

0 comments on commit 4710751

Please sign in to comment.