-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/sockets: socket_set_option switch from convert_to_long to zval_tr… #17135
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
7 commits
Select commit
Hold shift + click to select a range
0e4eeda
ext/sockets: socket_set_option switch from convert_to_long to zval_tr…
devnexen 45270c6
add test
devnexen 695861e
changes from review
devnexen 6c5f436
add test case
devnexen 1a14443
changes from review also attempt to prevent UB with timeout on windows.
devnexen e18fbb3
remove UB check and using zval_get_long instead
devnexen d6e64e6
other changes from review
devnexen 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
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,66 @@ | ||
--TEST-- | ||
socket_set_option() with SO_RCVTIMEO/SO_SNDTIMEO/SO_LINGER | ||
--EXTENSIONS-- | ||
sockets | ||
--FILE-- | ||
<?php | ||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
if (!$socket) { | ||
die('Unable to create AF_INET socket [socket]'); | ||
} | ||
$options_1 = array("sec" => 1, "usec" => "aaaaa"); | ||
$options_2 = array("sec" => new stdClass(), "usec" => "1"); | ||
$options_3 = array("l_onoff" => "aaaa", "l_linger" => "1"); | ||
$options_4 = array("l_onoff" => "1", "l_linger" => []); | ||
$options_5 = array("l_onoff" => PHP_INT_MAX, "l_linger" => "1"); | ||
|
||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, new stdClass); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, $options_1); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
|
||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_SNDTIMEO, $options_2); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, "not good"); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, "not good neither"); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_3); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_4); | ||
} catch (\TypeError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
try { | ||
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_5); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage() . PHP_EOL; | ||
} | ||
?> | ||
--EXPECTF-- | ||
socket_set_option(): Argument #4 ($value) must have key "sec" | ||
|
||
Warning: Object of class stdClass could not be converted to int in %s on line %d | ||
socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_RCVTIMEO, string given | ||
socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_LINGER, string given | ||
socket_set_option(): Argument #4 ($value) "l_onoff" must be between 0 and %d |
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.
This is the only "detail" I'm not sure about regarding BC: is it okay to drop support for
stdClass
,ArrayObject
and purpose built "data classes" (and maybe even objects in general)?Maybe wait what @Girgias (or others) have to say about this.
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.
If you are talking about the warning, I don't see how this is a BC breaks.
All the cases you mention already trigger this warning.
If you are talking about not supporting casting random objects to arrays, that is a recurring "problem" with PHP objects being structs, reference pointers, and everything in between. I don't think it is a problem is properly documented in UPGRADING for master, as most functions do not allow objects in those cases. Nor does ZPP unless one uses the special
Z_PARAM_ARRAY_OR_OBJECT(_*)
specifier (orA
/H
for non-fast ZPP).Moreover, this causes issues when the value in question possibly needs to be interpreted like a
string
.However, as this is a bugfix, I would do
if (zval != IS_ARRAY) { /* slow path */ if (zval != IS_OBJECT) { /* throw */ } else { /* get HT from props */ } }
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.
I was referring to the BC if we apply to stable branches (it's okay to be more strict for master).