From 5127953d3ed929a8643cfebbf7961a82e448e332 Mon Sep 17 00:00:00 2001 From: James O'Shannessy <12959316+joshanne@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:05:42 +1100 Subject: [PATCH] modules: add sanity checking to bitmask index when setting bitmask parameter --- MAVProxy/modules/mavproxy_param.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAVProxy/modules/mavproxy_param.py b/MAVProxy/modules/mavproxy_param.py index a4da69a43b..3f828b4577 100644 --- a/MAVProxy/modules/mavproxy_param.py +++ b/MAVProxy/modules/mavproxy_param.py @@ -387,6 +387,7 @@ def param_bitmask_modify(self, master, args): '''command for performing bitmask actions on a parameter''' BITMASK_ACTIONS = ['toggle', 'set', 'clear'] + NUM_BITS_MAX = 32 # Ensure we have at least an action and a parameter if len(args) < 2: @@ -474,6 +475,11 @@ def param_bitmask_modify(self, master, args): # We don't have enough information to modify the bitmask, so bail return + # Sanity check the bit index + if bit_index >= NUM_BITS_MAX: + print(f"Cannot perform bitmask action '{action}' on bit index {bit_index}.") + return + # We have enough information to try perform an action if action == "toggle": value = value ^ (1 << bit_index)