Skip to content

addTrackedObject Function Fails to Handle Null Pointer, Causing Crash When nullptr is Passed (backport #1375) #1379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rviz_common/src/rviz_common/interaction/selection_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void SelectionHandler::addTrackedObjects(Ogre::SceneNode * node)

void SelectionHandler::addTrackedObject(Ogre::MovableObject * object)
{
if (!object) {
// If object is nullptr, return immediately without further processing
return;
}

tracked_objects_.insert(object);
object->setListener(listener_.get());

Expand Down
5 changes: 5 additions & 0 deletions rviz_common/test/interaction/selection_handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,8 @@ TEST_F(SelectionHandlerFixture, onDeselect_removes_wirebox_around_object) {
Not(
ContainsWireBoxWithBoundingBox(Ogre::AxisAlignedBox(-2.0f, -2.0f, 0.0f, 2.0f, 2.0f, 0.0f))));
}

TEST_F(SelectionHandlerFixture, addTrackedObject_invalid_pointer_does_not_crash) {
Ogre::MovableObject * invalid_object = nullptr;
EXPECT_NO_THROW(handler_->addTrackedObject(invalid_object));
}