sccb-ng: fix off-by-one device capacity check to prevent overflow #771
+1
−1
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.
Description
SCCB_Install_Device() rejected new devices only when device_count > MAX_DEVICES. When device_count == MAX_DEVICES the function still proceeded to install the device and wrote to devices[device_count], i.e. devices[MAX_DEVICES], which is one element past the end of the devices[] array (valid indices 0..MAX_DEVICES-1).
This off-by-one results in a buffer overflow / write outside the designated memory area and then increments device_count to MAX_DEVICES+1.
Change the guard to
device_count >= MAX_DEVICES
so we refuse installation once the array is full and prevent the out-of-bounds write/read chain.Checklist
Before submitting a Pull Request, please ensure the following: