From 7f97e897e26310bc9e07aec2db8c44ae08dbc2d5 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 10 Jul 2024 22:41:02 +1000 Subject: [PATCH] AP_Camera: add sanity check for Siyi lens change --- libraries/AP_Mount/AP_Mount_Siyi.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Mount/AP_Mount_Siyi.cpp b/libraries/AP_Mount/AP_Mount_Siyi.cpp index 2202446b92..2158eb6dad 100644 --- a/libraries/AP_Mount/AP_Mount_Siyi.cpp +++ b/libraries/AP_Mount/AP_Mount_Siyi.cpp @@ -916,7 +916,7 @@ bool AP_Mount_Siyi::set_lens(uint8_t lens) } // maps lens to siyi camera image type so that lens of 0, 1, 2 are more useful - static CameraImageType cam_image_type_table[9] = { + static const CameraImageType cam_image_type_table[] { CameraImageType::MAIN_ZOOM_SUB_THERMAL, // 3 CameraImageType::MAIN_WIDEANGLE_SUB_THERMAL, // 5 CameraImageType::MAIN_THERMAL_SUB_ZOOM, // 7 @@ -928,6 +928,10 @@ bool AP_Mount_Siyi::set_lens(uint8_t lens) CameraImageType::MAIN_THERMAL_SUB_WIDEANGLE, // 8 }; + if (lens >= ARRAY_SIZE(cam_image_type_table)) { + return false; + } + // send desired image type to camera return send_1byte_packet(SiyiCommandId::SET_CAMERA_IMAGE_TYPE, (uint8_t)cam_image_type_table[lens]); }