mixer_{multicopter,helicopter}: add buffer size check

Fixes a potential buffer overflow if an MC/helicopter mixer is used that
exceeds the number of physical pins.
This is not a useful/flyable configuration, but the system still should
not crash.
This commit is contained in:
Beat Küng 2019-10-16 11:35:38 +02:00
parent 173337e49c
commit 617f37afbf
2 changed files with 8 additions and 0 deletions

View File

@ -200,6 +200,10 @@ HelicopterMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl
unsigned
HelicopterMixer::mix(float *outputs, unsigned space)
{
if (space < _mixer_info.control_count + 1u) {
return 0;
}
/* Find index to use for curves */
float thrust_cmd = get_control(0, 3);
int idx = (thrust_cmd / 0.25f);

View File

@ -354,6 +354,10 @@ void MultirotorMixer::mix_yaw(float yaw, float *outputs)
unsigned
MultirotorMixer::mix(float *outputs, unsigned space)
{
if (space < _rotor_count) {
return 0;
}
float roll = math::constrain(get_control(0, 0) * _roll_scale, -1.0f, 1.0f);
float pitch = math::constrain(get_control(0, 1) * _pitch_scale, -1.0f, 1.0f);
float yaw = math::constrain(get_control(0, 2) * _yaw_scale, -1.0f, 1.0f);