mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 11:59:17 +08:00
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:
@@ -200,6 +200,10 @@ HelicopterMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl
|
|||||||
unsigned
|
unsigned
|
||||||
HelicopterMixer::mix(float *outputs, unsigned space)
|
HelicopterMixer::mix(float *outputs, unsigned space)
|
||||||
{
|
{
|
||||||
|
if (space < _mixer_info.control_count + 1u) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Find index to use for curves */
|
/* Find index to use for curves */
|
||||||
float thrust_cmd = get_control(0, 3);
|
float thrust_cmd = get_control(0, 3);
|
||||||
int idx = (thrust_cmd / 0.25f);
|
int idx = (thrust_cmd / 0.25f);
|
||||||
|
|||||||
@@ -354,6 +354,10 @@ void MultirotorMixer::mix_yaw(float yaw, float *outputs)
|
|||||||
unsigned
|
unsigned
|
||||||
MultirotorMixer::mix(float *outputs, unsigned space)
|
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 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 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);
|
float yaw = math::constrain(get_control(0, 2) * _yaw_scale, -1.0f, 1.0f);
|
||||||
|
|||||||
Reference in New Issue
Block a user