Skip to content

Fix GH-25989: Unix socket peer name read from uninitialized memory - #25990

Open
matyapiro31 wants to merge 3 commits into
php:PHP-8.4from
matyapiro31:fix/gh25989-unix-peername-uninit
Open

matyapiro31 wants to merge 3 commits into
php:PHP-8.4from
matyapiro31:fix/gh25989-unix-peername-uninit

Conversation

@matyapiro31

Copy link
Copy Markdown
Contributor

Fixes GH-25989.

php_network_populate_name_from_sockaddr() read sun_path of an AF_UNIX address without regard to the length (sl) returned by the kernel. For an unnamed peer (a client that never bind()s) sl == sizeof(sa_family_t), so sun_path[0] and the subsequent strlen() 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:

  • Bound all sun_path accesses by sl; return an empty name when no path was provided.
  • Replace strlen() with a memchr() bounded by the valid length.
  • Add a test for the unnamed-client case. Note the bug depends on stack garbage, so the test passes deterministically after the fix but may also pass before it; it is mainly useful under Valgrind/MSan.

Testing: main/network.c was 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

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>
@devnexen

devnexen commented Dec 1, 2026

Copy link
Copy Markdown
Member

Testing: main/network.c was 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.

I did locally, the last test output expectation is wrong. The fix itself however is correct.

matyapiro31 and others added 2 commits December 1, 2026 05:36
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants