Skip to content

Don't let malformed set_parameters requests crash the node - #3256

Open
baszalmstra wants to merge 1 commit into
ros2:rollingfrom
baszalmstra:fix/set-parameters-service-uncaught-exception
Open

Don't let malformed set_parameters requests crash the node#3256
baszalmstra wants to merge 1 commit into
ros2:rollingfrom
baszalmstra:fix/set-parameters-service-uncaught-exception

Conversation

@baszalmstra

Copy link
Copy Markdown

The default parameter services crash the whole node on a malformed set_parameters request. Both handlers only catch ParameterNotDeclaredException, but an empty name (InvalidParametersException) or an unknown value type (UnknownTypeError from from_parameter_msg) escapes the callback and spin(), taking the node down. With no access control by default, any peer on the graph can trigger it.

Both handlers now catch std::exception and return an unsuccessful result. I also moved the from_parameter_msg conversion in the atomic handler inside the try, which the unknown-type case there wasn't covered by before.

Testing

Added regression tests for both services (empty name via the typed client, unknown type via a raw client). I couldn't build Rolling locally, so I'd like CI to confirm; the crash itself reproduces with a single ros2 service call to /<node>/set_parameters using {name: ''}.

The set_parameters and set_parameters_atomically service handlers only
caught ParameterNotDeclaredException. A request carrying a parameter with
an empty name (InvalidParametersException) or an unknown value type
(UnknownTypeError, thrown by Parameter::from_parameter_msg) let the
exception escape the service callback, unwind through the executor's
spin(), and terminate the node -- an unauthenticated remote DoS on any
node exposing the default parameter services.

Broaden both handlers to catch std::exception and return an unsuccessful
SetParametersResult instead. In the atomic handler, move the
from_parameter_msg conversion inside the try so an unknown type raised
during conversion is handled too.

Adds regression tests covering empty name (typed client) and unknown
type (raw client) for both services.

Signed-off-by: Bas Zalmstra <4995967+baszalmstra@users.noreply.github.com>
@baszalmstra
baszalmstra force-pushed the fix/set-parameters-service-uncaught-exception branch from 0042af5 to 1434554 Compare September 4, 2026 10:09
result = node_params->set_parameters_atomically(
{rclcpp::Parameter::from_parameter_msg(p)});
} catch (const rclcpp::exceptions::ParameterNotDeclaredException & ex) {
} catch (const std::exception & ex) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could scope this to just a handful of relevant exceptions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then as soon as a new exception is added you can introduce the same crash. What does scoping add here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment here #3257 (comment)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catchalls are considered back practice as you might also catch exceptions that were not meant to be catched.
You can also give better error messages depending on the type of exception you are catching...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that backporting is desirable, what is the best type to use in this case? std::runtime_error?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catchalls are considered back practice as you might also catch exceptions that were not meant to be catched. You can also give better error messages depending on the type of exception you are catching...

Totally agreed but arguably completely missed exceptions also bad practice. I think catching broadly here fixes the current issue but to properly fix this with best practices, all throws in this repo should be re-evalued to be sure no generic exceptions are being thrown. Obviously this was already started from humble > rolling with that TODO I linked fixed, just this would be another case. I suppose the backport to humble for this exact issue could include fixing that generic throw. I will leave it to the folks implementing but that's my $0.02.

@skyegalaxy

Copy link
Copy Markdown
Member

Pulls: #3256
Gist: https://gist.githubusercontent.com/skyegalaxy/260e0379030fe57e961d15e11c7b336c/raw/fc70d74e12521db983b1711b7074eed26476c99c/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/20336

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed SetParameters request with invalid type crashes rclcpp node

4 participants