Skip to content

Commit 079a717

Browse files
Cryst4L9527SteveMacenski
authored andcommitted
map-size restriction to avoid overflow and nullptr caused by user-misconfiguration (#3242)
* odom alpha restriction * odom alpha code style * odom alpha code style * odom alpha code style * map-size restriction * map-size code style * map-size rejection * map-size codestyle * map-size return false
1 parent 28474a9 commit 079a717

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

nav2_costmap_2d/src/costmap_2d_ros.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,27 @@ Costmap2DROS::dynamicParametersCallback(std::vector<rclcpp::Parameter> parameter
637637
}
638638
} else if (type == ParameterType::PARAMETER_INTEGER) {
639639
if (name == "width") {
640-
resize_map = true;
641-
map_width_meters_ = parameter.as_int();
640+
if (parameter.as_int() > 0) {
641+
resize_map = true;
642+
map_width_meters_ = parameter.as_int();
643+
} else {
644+
RCLCPP_ERROR(
645+
get_logger(), "You try to set width of map to be negative or zero,"
646+
" this isn't allowed, please give a positive value.");
647+
result.successful = false;
648+
return result;
649+
}
642650
} else if (name == "height") {
643-
resize_map = true;
644-
map_height_meters_ = parameter.as_int();
651+
if (parameter.as_int() > 0) {
652+
resize_map = true;
653+
map_height_meters_ = parameter.as_int();
654+
} else {
655+
RCLCPP_ERROR(
656+
get_logger(), "You try to set height of map to be negative or zero,"
657+
" this isn't allowed, please give a positive value.");
658+
result.successful = false;
659+
return result;
660+
}
645661
}
646662
} else if (type == ParameterType::PARAMETER_STRING) {
647663
if (name == "footprint") {

0 commit comments

Comments
 (0)