ext/sockets: bound interface name copy in from_zval_write_ifindex()#104
Closed
iliaal wants to merge 1 commit into
Closed
ext/sockets: bound interface name copy in from_zval_write_ifindex()#104iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
The SIOCGIFINDEX fallback checked ZSTR_LEN against sizeof(ifr.ifr_name) but did not return on overflow, then memcpy'd ZSTR_LEN+1 bytes into the fixed ifr_name buffer, so an over-long interface name overran the stack. This regressed in 3e9b530, which replaced the original bounded strlcpy with an unguarded memcpy. Restore the strlcpy plus else-if guard, matching PHP-8.4 and PHP-8.5.
Owner
Author
|
Submitted upstream as php#22379. |
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.
The SIOCGIFINDEX fallback in from_zval_write_ifindex() checks ZSTR_LEN against sizeof(ifr.ifr_name) but does not return on overflow, then memcpy's ZSTR_LEN+1 bytes into the fixed-size ifr_name stack buffer, so an over-long interface name passed to socket_sendmsg() IPV6_PKTINFO overruns the stack. This regressed in 3e9b530 (php#17311), which replaced the original bounded strlcpy with an unguarded memcpy; PHP-8.4 and PHP-8.5 are unaffected. The fix restores the strlcpy plus else-if guard from the stable branches. The branch is only compiled where if_nametoindex() is unavailable, so it is not built on mainstream Linux/CI and there is no automated test; verified by inspection against the stable-branch code.