fix(rc_update): treat an RC_MAP_* channel past the channel array as unassigned

Each RC_MAP_* parameter became a channel index with `map - 1`, and the
readers only checked the lower bound before indexing the 18-entry
channel array. The declared range 0..18 is not enforced on the way in,
so a map of 19 or more read past the array; only the throttle special
case was bounded.

Add rc_map_index(), which maps 1..RC_INPUT_MAX_CHANNELS to an index and
anything else to -1, use it for every map and for the mode-slot read.
Add an RCUpdateTest case with RC_MAP_FLTMODE = 19 expecting no mode slot.
This commit is contained in:
treston authored and Matthias Grob committed 2026-10-13 14:49:20 +02:00
1 parent 07a2faab0d
commit bb12e7dc75
2 files changed
+54 -23

No files matched your search

+20
View File
@@ -180,6 +180,26 @@ TEST_F(RCUpdateTest, ModeSlotUnassigned)
EXPECT_EQ(manual_control_switches_sub.get().mode_slot, 0); // manual_control_switches_s::MODE_SLOT_NONE
}
TEST_F(RCUpdateTest, ModeSlotMapBeyondChannelsIsUnassigned)
{
// GIVEN: the mode switch is mapped to a channel past the channel array (the parameter range is not enforced)
_param_rc_map_fltmode.set(19);
_param_rc_map_fltmode.commit();
EXPECT_EQ(_param_rc_map_fltmode.get(), 19);
_rc_update.updateParams();
// WHEN: we update the switches two times to pass the simple outlier protection
_rc_update.UpdateManualSwitches(0);
_rc_update.UpdateManualSwitches(0);
// THEN: the map counts as unassigned instead of reading beyond the channels
uORB::SubscriptionData<manual_control_switches_s> manual_control_switches_sub{ORB_ID(manual_control_switches)};
EXPECT_EQ(manual_control_switches_sub.get().mode_slot, manual_control_switches_s::MODE_SLOT_NONE);
_param_rc_map_fltmode.set(0);
_param_rc_map_fltmode.commit();
}
TEST_F(RCUpdateTest, ModeSlotSwitchAllValues)
{
checkModeSlotSwitch(-1.f, 1); // manual_control_switches_s::MODE_SLOT_1