Prevent OOB POWER_VALUES array access #3458
Merged
+16
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prevents out-of-bounds array access if the number of items in a POWER_LEVELS_X array doesn't have as many items as MaxPower - MinPower. Instead of the existing code which returns whatever data is in RAM after the POWER_LEVELS array, this returns the value for MinPower.
This is for when a user sees the hardware page will let them convert their 10mW device into a 2000mW device simply by changing MaxPower, which then causes the radio to output random power currently-- possibly damaging the PA. Hopefully they will see that their range is low on 2000mW and realize the page is for letting the user know what the hardware can do, and not for telling the hardware what to be.
Also removed an unused variables and don't store pointers to the VALUES array locally. The lookup is fast enough for the frequency that this data will be accessed.
Backport
We can consider backporting this but given this has been like this the entire time we've had Unified firmware, and the relative obscurity of hardware.html, I don't think it is critical enough.