Repository navigation
Fix GH-25989: Unix socket peer name read from uninitialized memory - #25990
Open
matyapiro31 wants to merge 3 commits into
Open
matyapiro31 wants to merge 3 commits into
matyapiro31 wants to merge 3 commits into
Conversation
php_network_populate_name_from_sockaddr() accessed sun_path without considering the address length returned by the kernel. For an unnamed AF_UNIX peer (a client that never bind()s) the length is only sizeof(sa_family_t), so sun_path[0] and the following strlen() read uninitialized stack memory. Bound all accesses by sl and return an empty name for unnamed peers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
I did locally, the last test output expectation is wrong. The fix itself however is correct. |
An empty peer name is reported as false by stream_socket_get_name(). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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 GH-25989.
php_network_populate_name_from_sockaddr()readsun_pathof anAF_UNIXaddress without regard to the length (sl) returned by the kernel. For an unnamed peer (a client that neverbind()s)sl == sizeof(sa_family_t), sosun_path[0]and the subsequentstrlen()read uninitialized stack memory.This is a code-quality fix, not a security issue: all accesses are reads, and the stale bytes are PHP's own stack contents that the peer cannot control.
Changes:
sun_pathaccesses bysl; return an empty name when no path was provided.strlen()with amemchr()bounded by the valid length.Testing:
main/network.cwas syntax-checked with MSVC (cl /Zs); I could not run the phpt locally (no working full build in my environment), so please rely on CI for that.🤖 Generated with Claude Code