From a50004baffb05ce92656e3db5828933acebfb743 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 25 Jun 2019 12:56:48 +1000 Subject: [PATCH] Rover: add sanity check when fetching GCS_MAVLink instance --- APMrover2/GCS_Rover.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/APMrover2/GCS_Rover.h b/APMrover2/GCS_Rover.h index fe0151c445..abb0f553ba 100644 --- a/APMrover2/GCS_Rover.h +++ b/APMrover2/GCS_Rover.h @@ -13,9 +13,21 @@ public: uint8_t num_gcs() const override { return ARRAY_SIZE(_chan); }; // return GCS link at offset ofs - GCS_MAVLINK_Rover &chan(const uint8_t ofs) override { return _chan[ofs]; }; + GCS_MAVLINK_Rover &chan(uint8_t ofs) override { + if (ofs >= num_gcs()) { + AP::internalerror().error(AP_InternalError::error_t::gcs_offset); + ofs = 0; + } + return _chan[ofs]; + } // return GCS link at offset ofs - const GCS_MAVLINK_Rover &chan(const uint8_t ofs) const override { return _chan[ofs]; }; + const GCS_MAVLINK_Rover &chan(uint8_t ofs) const override { + if (ofs >= num_gcs()) { + AP::internalerror().error(AP_InternalError::error_t::gcs_offset); + ofs = 0; + } + return _chan[ofs]; + } uint32_t custom_mode() const override; MAV_TYPE frame_type() const override;