Skip to content

Commit 5127953

Browse files
joshannepeterbarker
authored andcommitted
modules: add sanity checking to bitmask index when setting bitmask parameter
1 parent d8a28aa commit 5127953

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

MAVProxy/modules/mavproxy_param.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ def param_bitmask_modify(self, master, args):
387387
'''command for performing bitmask actions on a parameter'''
388388

389389
BITMASK_ACTIONS = ['toggle', 'set', 'clear']
390+
NUM_BITS_MAX = 32
390391

391392
# Ensure we have at least an action and a parameter
392393
if len(args) < 2:
@@ -474,6 +475,11 @@ def param_bitmask_modify(self, master, args):
474475
# We don't have enough information to modify the bitmask, so bail
475476
return
476477

478+
# Sanity check the bit index
479+
if bit_index >= NUM_BITS_MAX:
480+
print(f"Cannot perform bitmask action '{action}' on bit index {bit_index}.")
481+
return
482+
477483
# We have enough information to try perform an action
478484
if action == "toggle":
479485
value = value ^ (1 << bit_index)

0 commit comments

Comments
 (0)