Repository navigation
Conversation
parse_ip_address_ex() and php_network_parse_network_address_with_port() read the port with atoi() and did not check its range, so a port above 65535 or below 0 silently wrapped to another port. Reject such ports. bug69521.phpt relied on this wrapping (port 74321), use an ephemeral port instead.
devnexen
approved these changes
Oct 24, 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.
parse_ip_address_ex()inmain/streams/xp_socket.creads the port withatoi()and does not check its range. The port is later narrowed tounsigned short, so a port above 65535 (or a negative one) wraps to another port.fsockopen(),stream_socket_client()andstream_socket_server(), for bothtcp://andudp://, connect to or bind the wrong port:php_network_parse_network_address_with_port()inmain/network.c(used for the target address ofstream_socket_sendto()) has the sameatoi()pattern, and stores the result in ashort.Fix
Parse the port with
ZEND_STRTOL()and reject values outside 0..65535. Inparse_ip_address_ex(), this applies to both the plain and the[IPv6]:portforms, and fails withFailed to parse port of address "..."(like the existingFailed to parse address "..."errors).php_network_parse_network_address_with_port()returnsFAILURE, sostream_socket_sendto()reports its existing "Failed to parse ... into a valid network address" warning.Everything else that
atoi()accepted is still accepted, for example trailing characters after the port and an empty port (port 0), to keep the change small for a stable branch. An out-of-range port in thebindtocontext option is now handled like any otherbindtovalue that does not parse (it is ignored, as before for unparsable values).ext/standard/tests/streams/bug69521.phptused port 74321 and so relied on this wrap (it actually listened on 8785). It now uses an ephemeral port.Test
ext/standard/tests/network/gh24616.phptuses port + 65536 of a listening server withstream_socket_client(),fsockopen()and the IPv6 form. It also tries negative and very large ports,stream_socket_server()on 65536, andstream_socket_sendto()to a UDP port + 65536. Then it checks that the real port still connects.fsockopen()calls return a connected stream,stream_socket_server()binds, andstream_socket_sendto()sends 1 byte.ext/standard/tests/network,ext/standard/tests/streamsandext/standard/tests/file(debug build): 807 passed, 323 skipped, 0 failed.This rejects input that was accepted before, so if you prefer to treat it as a behaviour change, I can retarget it to master.
Fixes GH-24616
This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually; the patch was manually reviewed.
🤖 Generated with Claude Code