Skip to content

Commit

Permalink
modules: add sanity checking to bitmask index when setting bitmask pa…
Browse files Browse the repository at this point in the history
…rameter
  • Loading branch information
joshanne authored and peterbarker committed Dec 16, 2024
1 parent d8a28aa commit 5127953
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MAVProxy/modules/mavproxy_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5127953

Please sign in to comment.