Fix link-layer address enumeration on macOS - #131803
Open
wfurt wants to merge 2 commits into
Open
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Unix System.Native interface-address enumeration and its managed interop to safely handle link-layer (AF_LINK / sockaddr_dl) addresses that can exceed the previously assumed 8-byte buffer, particularly on macOS.
Changes:
- Expand link-layer address storage in native PAL structs and managed interop structs from 8 to 12 bytes.
- Clamp the link-layer address copy length to both the source record’s reported capacity and the destination buffer size (including a SunOS-specific path where
sdl_lenisn’t available). - Add native compile-time assertions to validate the interop struct layout assumptions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/native/libs/System.Native/pal_interfaceaddresses.h | Expands native struct link-layer address buffers to 12 bytes. |
| src/native/libs/System.Native/pal_interfaceaddresses.c | Adds length-clamping helper for AF_LINK and updates copies + adds layout assertions. |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs | Updates managed interop structs to match the new 12-byte native buffers. |
Suppressed comments (1)
src/native/libs/System.Native/pal_interfaceaddresses.c:471
- Same as above:
LLADDR(sadl)is computed even whenNumAddressBytesclamps to 0. Guarding the copy avoids forming a potentially out-of-bounds pointer for malformed/short records.
memcpy_s(&nii->AddressBytes, sizeof_member(NetworkInterfaceInfo, AddressBytes), (uint8_t*)LLADDR(sadl), nii->NumAddressBytes);
This was referenced Aug 4, 2026
Open
rzikm
approved these changes
Aug 5, 2026
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 #125711
Summary
sdl_datacapacity on SunOS, wheresockaddr_dldoes not exposesdl_lenThe hardware-specific scenario requires a special link-layer adapter and was not reproduced locally. The bounds and layouts were validated through native compilation, the existing macOS interface enumeration tests, and specialist review.
Testing
./build.sh libs.native./dotnet.sh build /t:test src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj(246 passed)Note
This pull request description was generated with GitHub Copilot.