From 8638fa397e377f106e3eb2e48b66648af609aed8 Mon Sep 17 00:00:00 2001 From: mumumu Date: Tue, 17 Nov 2026 07:44:56 +0800 Subject: [PATCH] fix(control_allocator): reject negative tilt indices (#29797) CA_ROTORn_TILT is declared as an enum (0..4), but parameter ranges are not enforced by param_set(). ActuatorEffectivenessRotors::updateParams() stores tilt_param - 1 directly, and both consumers only skip the sentinel value -1. Any value below -1 therefore indexes _params[] and _torque[] with a negative index, which crashes the control allocator on the next parameter update. Treat every negative index as "not tilted" in updateTorqueSign() and updateAxisFromTilts(). Test: main SITL, CA_AIRFRAME=8 + CA_ROTOR0_TILT=-100000 (SIGSEGV in ActuatorEffectivenessTilts::updateTorqueSign) Assisted-by: deepseek Signed-off-by: Summermu <23356722+Summermu@users.noreply.github.com> Co-authored-by: Summermu <23356722+Summermu@users.noreply.github.com> --- .../ActuatorEffectivenessRotors.cpp | 2 +- .../VehicleActuatorEffectiveness/ActuatorEffectivenessTilts.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessRotors.cpp b/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessRotors.cpp index 185add56acf..fb074e7bf94 100644 --- a/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessRotors.cpp +++ b/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessRotors.cpp @@ -234,7 +234,7 @@ ActuatorBitmask ActuatorEffectivenessRotors::updateAxisFromTilts(const ActuatorE for (int i = 0; i < _geometry.num_rotors; ++i) { int tilt_index = _geometry.rotors[i].tilt_index; - if (tilt_index == -1 || tilt_index >= tilts.count()) { + if (tilt_index < 0 || tilt_index >= tilts.count()) { nontilted_motors |= 1u << i; continue; } diff --git a/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTilts.cpp b/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTilts.cpp index 31a6ab2b77e..2fd77a805fd 100644 --- a/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTilts.cpp +++ b/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTilts.cpp @@ -107,7 +107,7 @@ void ActuatorEffectivenessTilts::updateTorqueSign(const ActuatorEffectivenessRot for (int i = 0; i < geometry.num_rotors; ++i) { int tilt_index = geometry.rotors[i].tilt_index; - if (tilt_index == -1 || tilt_index >= _count) { + if (tilt_index < 0 || tilt_index >= _count) { continue; }