Skip to content

Commit 77c79de

Browse files
committed
ext/sockets: Fix socket_set_option() validation error messages
1 parent 27e3f6b commit 77c79de

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Date:
66
. Fixed leak on double DatePeriod::__construct() call. (ilutov)
77

8+
- Sockets:
9+
. Fixed socket_set_option() validation error messages for UDP_SEGMENT and
10+
SO_LINGER options. (Weilin Du)
11+
812
30 Jul 2026, PHP 8.5.9
913

1014
- Core:

ext/sockets/sockets.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ PHP_FUNCTION(socket_set_option)
21682168
}
21692169

21702170
if (val_linger < 0 || val_linger > USHRT_MAX) {
2171-
zend_argument_value_error(4, "\"%s\" must be between 0 and %d", l_linger, USHRT_MAX);
2171+
zend_argument_value_error(4, "\"%s\" must be between 0 and %u", l_linger_key, USHRT_MAX);
21722172
RETURN_THROWS();
21732173
}
21742174

@@ -2332,8 +2332,8 @@ PHP_FUNCTION(socket_set_option)
23322332

23332333
// UDP segmentation offload maximum size or 0 to disable it
23342334
if (ov < 0 || ov > USHRT_MAX) {
2335-
zend_argument_value_error(4, "must be of between 0 and %u", USHRT_MAX);
2336-
RETURN_FALSE;
2335+
zend_argument_value_error(4, "must be between 0 and %u", USHRT_MAX);
2336+
RETURN_THROWS();
23372337
}
23382338

23392339
optlen = sizeof(ov);

ext/sockets/tests/socket_cmsg_udp_segment.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ try {
2222
}
2323
?>
2424
--EXPECT--
25-
socket_setopt(): Argument #4 ($value) must be of between 0 and 65535
26-
socket_setopt(): Argument #4 ($value) must be of between 0 and 65535
25+
socket_setopt(): Argument #4 ($value) must be between 0 and 65535
26+
socket_setopt(): Argument #4 ($value) must be between 0 and 65535

ext/sockets/tests/socket_set_option_timeo_error.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ $options_2 = array("sec" => new stdClass(), "usec" => "1");
1313
$options_3 = array("l_onoff" => "aaaa", "l_linger" => "1");
1414
$options_4 = array("l_onoff" => "1", "l_linger" => []);
1515
$options_5 = array("l_onoff" => PHP_INT_MAX, "l_linger" => "1");
16+
$options_6 = array("l_onoff" => "1", "l_linger" => PHP_INT_MAX);
1617

1718
try {
1819
socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, new stdClass);
@@ -56,6 +57,11 @@ try {
5657
} catch (\ValueError $e) {
5758
echo $e->getMessage() . PHP_EOL;
5859
}
60+
try {
61+
socket_set_option( $socket, SOL_SOCKET, SO_LINGER, $options_6);
62+
} catch (\ValueError $e) {
63+
echo $e->getMessage() . PHP_EOL;
64+
}
5965
?>
6066
--EXPECTF--
6167
socket_set_option(): Argument #4 ($value) must have key "sec"
@@ -64,3 +70,4 @@ Warning: Object of class stdClass could not be converted to int in %s on line %d
6470
socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_RCVTIMEO, string given
6571
socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is SO_LINGER, string given
6672
socket_set_option(): Argument #4 ($value) "l_onoff" must be between 0 and %d
73+
socket_set_option(): Argument #4 ($value) "l_linger" must be between 0 and %d

0 commit comments

Comments
 (0)