Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules: add sanity checking to bitmask index when setting bitmask parameter #1494

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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