Repository navigation
Fix GH-24748: socket_set_option() crash with declared object properties #24749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d816e1e
Fix GH-24748: socket_set_option() crash with declared object properties
lazerg 1e99a2a
Read each socket option value before looking up the next one
lazerg 37088c0
Keep the object property table alive while reading socket option values
lazerg dfd1211
Only compare l_linger in the GH-24748 test, BSD reports l_onoff as 128
lazerg 2f771be
Fall back to an empty table when an object has no properties table
lazerg 312d69e
Use the l_linger key name in the SO_LINGER range error, drop NEWS entry
lazerg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --TEST-- | ||
| GH-24748 (socket_set_option() crashes when the value is an object with declared properties) | ||
| --EXTENSIONS-- | ||
| sockets | ||
| --FILE-- | ||
| <?php | ||
| class Linger { | ||
| public $l_onoff = 1; | ||
| public $l_linger = 5; | ||
| } | ||
|
|
||
| class Timeout { | ||
| public $sec = 1; | ||
| public int $usec; | ||
| } | ||
|
|
||
| $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
| var_dump(socket_set_option($socket, SOL_SOCKET, SO_LINGER, new Linger())); | ||
| var_dump(socket_get_option($socket, SOL_SOCKET, SO_LINGER)["l_linger"]); | ||
|
|
||
| try { | ||
| socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, new Timeout()); | ||
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| $timeout = new Timeout(); | ||
| $timeout->usec = 0; | ||
| var_dump(socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout)); | ||
| var_dump(socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout)); | ||
| var_dump(socket_get_option($socket, SOL_SOCKET, SO_SNDTIMEO)); | ||
|
|
||
| $linger = new stdClass(); | ||
| $linger->l_onoff = new stdClass(); | ||
| $linger->l_linger = 5; | ||
| set_error_handler(function () use ($linger) { | ||
| $tmp = (array) $linger; | ||
| $linger->extra = 1; | ||
| unset($tmp); | ||
| return true; | ||
| }); | ||
| var_dump(socket_set_option($socket, SOL_SOCKET, SO_LINGER, $linger)); | ||
| restore_error_handler(); | ||
|
|
||
| try { | ||
| socket_set_option($socket, SOL_SOCKET, SO_LINGER, new ArrayObject(['l_onoff' => 1, 'l_linger' => 70000])); | ||
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| int(5) | ||
| socket_set_option(): Argument #4 ($value) must have key "usec" | ||
| bool(true) | ||
| bool(true) | ||
| array(2) { | ||
| ["sec"]=> | ||
| int(1) | ||
| ["usec"]=> | ||
| int(0) | ||
| } | ||
| bool(true) | ||
| socket_set_option(): Argument #4 ($value) "l_linger" must be between 0 and 65535 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zend_get_properties_for(..., ZEND_PROP_PURPOSE_ARRAY_CAST)can return a temporary table (for example,ArrayObjectreturns a duplicate). This release destroys that table, but the subsequent linger range-error formatter still passesl_lingerto%s, causing a use-after-free read.The incorrect format argument predates this PR; freeing its backing table before formatting introduces the lifetime defect. Please pass
l_linger_keyinstead ofl_lingertozend_argument_value_error()and add regression coverage for this validation path with a temporary property table.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 312d69e. The error now uses
l_linger_key, and gh24748.phpt covers it with an out-of-rangeArrayObject.