esp8266/network_wlan: Allow bytes() objects as MAC address.#19282
Open
agatti wants to merge 1 commit into
Open
esp8266/network_wlan: Allow bytes() objects as MAC address.#19282agatti wants to merge 1 commit into
agatti wants to merge 1 commit into
Conversation
dpgeorge
reviewed
May 31, 2026
This commit fixes a crash occurring when setting the WLAN MAC address using a bytes() object containing the new MAC address bytes. This also fixes cases where the address is put in ROM or is an unaligned slice of a larger buffer. The ESP8266's network stack seems to want the MAC address buffer being in a particular memory area and with a specific alignment, which cannot be always guaranteed. Luckily stack-allocated buffers do have the necessary requirements when it comes to location and alignment, so the MAC address is first copied into such a buffer and then that's passed to the network stack. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
442abd0 to
4c02566
Compare
Octoprobe PR report
Summary
|
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.
Summary
This PR fixes a crash occurring when setting the WLAN MAC address using a bytes() object containing the new MAC address bytes. This also fixes cases where the address is put in ROM or is an unaligned slice of a larger buffer.
The ESP8266's network stack seems to want the MAC address buffer being in a particular memory area and with a specific alignment, which cannot be always guaranteed. Luckily stack-allocated buffers do have the necessary requirements when it comes to location and alignment, so the MAC address is first copied into such a buffer and then that's passed to the network stack.
This fixes #11357.
Testing
The sample code fragments provided in #11357 were executed on a generic ESP8266 board, correctly setting the WLAN MAC address instead of crashing.
Trade-offs and Alternatives
This makes the firmware 76 bytes larger, which I believe is unavoidable in this case.
Generative AI
I did not use generative AI tools when creating this PR.