fix(MPU): promote attr to uint32_t before shifting in ARM_MPU_SetMemAttrEx#305
Open
saikumar-mandaji wants to merge 1 commit into
Open
fix(MPU): promote attr to uint32_t before shifting in ARM_MPU_SetMemAttrEx#305saikumar-mandaji wants to merge 1 commit into
saikumar-mandaji wants to merge 1 commit into
Conversation
…ttrEx attr is uint8_t. In `attr << pos`, integer promotion converts attr to a signed int before the shift; for attr >= 0x80 and pos == 24 the mathematical result (up to 0xFF000000) exceeds INT_MAX, which is undefined behavior for a signed left shift, not merely implementation-defined truncation. Fix: promote attr to uint32_t explicitly before shifting, so the shift is performed in unsigned arithmetic and cannot overflow, matching the fix suggested in the issue. Fixes ARM-software#169 Signed-off-by: Saikumar Mandaji <mandajisaikumar@gmail.com>
Test Results 292 files - 352 292 suites - 352 0s ⏱️ - 15m 56s Results for commit b418536. ± Comparison against base commit 7f62ddc. This pull request removes 49 and adds 56 tests. Note that renamed tests count towards both.This pull request removes 5 skipped tests and adds 2 skipped tests. Note that renamed tests count towards both. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #169
Problem
ARM_MPU_SetMemAttrExcomputesattr << poswhereattrisuint8_t. Integer promotion convertsattrto a signedintbefore the shift is evaluated. Forattr >= 0x80andpos == 24, the mathematical result (up to0xFF000000) exceedsINT_MAX, which is undefined behavior for a signed left shift -- not merely implementation-defined truncation.Fix
Promote
attrtouint32_texplicitly before shifting, so the shift is performed in unsigned arithmetic and cannot overflow, matching the fix suggested in the issue.Verification
Verified by hand against the issue's analysis (integer-promotion rules for
E1 << E2, and the resulting range forattr << posatpos == 24). No C compiler was available in the environment this patch was authored in, so I was not able to build/run against the test suite directly -- please double-check against CI/local build before merging.