shared/netutils: Factor mp_hal_get_mac_ascii out of ports. - #19674
pablogventura wants to merge 1 commit into
Conversation
|
Code size report: |
projectgus
left a comment
There was a problem hiding this comment.
The assert looks reasonable, but this looks like we should actually move this utility function somewhere else (maybe a new file in extmod/?) instead of maintaining five identical copies of it.
Move the identical helper from stm32/rp2/mimxrt/renesas-ra/alif into shared/netutils and assert the hex character slice stays within the 12-character MAC representation. Fixes micropython#19668. Signed-off-by: Pablo Ventura <pablogventura@gmail.com>
|
@projectgus Thanks for the review. Consolidated the five copies into |
2c86a33 to
cbf4ccd
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19674 +/- ##
==========================================
- Coverage 98.56% 98.55% -0.01%
==========================================
Files 182 182
Lines 23335 23335
Branches 5 5
==========================================
- Hits 22999 22998 -1
- Misses 335 336 +1
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Fixes #19668.
mp_hal_get_mac_asciiindexedmac[chr_off >> 1]without checking that the requested hex slice stays within the 12-character MAC representation, sochr_off == 12readmac[6].The same helper was duplicated in stm32, rp2, mimxrt, renesas-ra, and alif. Move it to
shared/netutils/get_mac_ascii.cand addassert(chr_off <= 12 && chr_len <= 12 - chr_off)in that single copy. In-tree callers use(8, 4)and are unchanged.Testing
get_mac_ascii.cinto each port's shared/netutils sourcesTrade-offs and Alternatives
assert(not a runtime clamp): zero cost in typical release builds withNDEBUG, matches other HAL programmer-error checks. Invalid callers still trap in assert-enabled builds.shared/netutilsrather than a newextmod/file: this is a portable C HAL helper (no Python module), and these ports already buildshared/netutils.No unix
.textdelta (port HAL / shared helper only).Generative AI
I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.