From bbc59dcde7698eb08fed80fad0ea7d03e4273816 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Wed, 20 Nov 2024 10:47:02 +0100 Subject: [PATCH] CollisionPrevention: prevent illegal array index with malicious obstacle_dsitance message --- src/lib/collision_prevention/CollisionPrevention.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/collision_prevention/CollisionPrevention.cpp b/src/lib/collision_prevention/CollisionPrevention.cpp index 7d34097644f2..691f13c4dffb 100644 --- a/src/lib/collision_prevention/CollisionPrevention.cpp +++ b/src/lib/collision_prevention/CollisionPrevention.cpp @@ -234,7 +234,7 @@ void CollisionPrevention::_addObstacleSensorData(const obstacle_distance_s &obst // Obstacle message arrives in local_origin frame (north aligned) // corresponding data index (convert to world frame and shift by msg offset) for (int i = 0; i < BIN_COUNT; i++) { - for (int j = 0; j < 360 / obstacle.increment; j++) { + for (int j = 0; (j < 360 / obstacle.increment) && (j < BIN_COUNT); j++) { float bin_lower_angle = _wrap_360((float)i * _obstacle_map_body_frame.increment + _obstacle_map_body_frame.angle_offset - (float)_obstacle_map_body_frame.increment / 2.f); float bin_upper_angle = _wrap_360((float)i * _obstacle_map_body_frame.increment + _obstacle_map_body_frame.angle_offset