From a4164375612f6f43bb6cb7cb5e2c13a1ac0a098f Mon Sep 17 00:00:00 2001 From: Silvan Date: Thu, 22 Jan 2026 16:06:02 +0100 Subject: [PATCH] rtl: guard access of dynamically created _rtl_mission_type_handle behind if() To avoid hard faults from NULL access. Signed-off-by: Silvan --- src/modules/navigator/rtl.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/modules/navigator/rtl.cpp b/src/modules/navigator/rtl.cpp index 9da6d5a7d9..1c9794893b 100644 --- a/src/modules/navigator/rtl.cpp +++ b/src/modules/navigator/rtl.cpp @@ -226,7 +226,10 @@ void RTL::on_activation() case RtlType::RTL_DIRECT_MISSION_LAND: // Fall through case RtlType::RTL_MISSION_FAST: // Fall through case RtlType::RTL_MISSION_FAST_REVERSE: - _rtl_mission_type_handle->setReturnAltMin(_enforce_rtl_alt); + if (_rtl_mission_type_handle) { + _rtl_mission_type_handle->setReturnAltMin(_enforce_rtl_alt); + } + break; case RtlType::RTL_DIRECT: @@ -635,19 +638,31 @@ void RTL::initRtlMissionType(RtlType new_rtl_type, float rtl_alt) switch (new_rtl_type) { case RtlType::RTL_DIRECT_MISSION_LAND: _rtl_mission_type_handle = new RtlDirectMissionLand(_navigator); - _rtl_mission_type_handle->setRtlAlt(rtl_alt); - _rtl_mission_type_handle->initialize(); + + if (_rtl_mission_type_handle) { + _rtl_mission_type_handle->setRtlAlt(rtl_alt); + _rtl_mission_type_handle->initialize(); + } + // RTL type is either direct or mission land have to set it later. break; case RtlType::RTL_MISSION_FAST: _rtl_mission_type_handle = new RtlMissionFast(_navigator, new_mission); - _rtl_mission_type_handle->initialize(); + + if (_rtl_mission_type_handle) { + _rtl_mission_type_handle->initialize(); + } + break; case RtlType::RTL_MISSION_FAST_REVERSE: _rtl_mission_type_handle = new RtlMissionFastReverse(_navigator, new_mission); - _rtl_mission_type_handle->initialize(); + + if (_rtl_mission_type_handle) { + _rtl_mission_type_handle->initialize(); + } + break; default: